-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make (delete) and (set) work with tuples/vectors/node, change (set) b…
…ehaviour to return the entire datastructure (closes #2)
- Loading branch information
Showing
10 changed files
with
300 additions
and
249 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,44 @@ | ||
# delete | ||
|
||
`delete` removes a key from an object or an item from a vector (shrinking that | ||
vector by 1 element). | ||
|
||
<!-- It must be used with a path expression and can be used | ||
on expressions that support path expressions (e.g. `(delete (do-something).gone)`). --> | ||
vector by 1 element). It must be used on any expression that has a path | ||
expression attached (e.g. `(delete (do-something).gone)`). | ||
|
||
Note that `delete` is, like all functions in Rudi, stateless and so does not | ||
modify the given argument directly. To make your changes "stick", use the bang | ||
modifier: `(delete! $var.foo)` – this only makes sense for symbols (i.e. | ||
variables and the global document), which is incidentally also what the bang | ||
modifier itself already enforces. So an expression like `(delete! [1 2][1])` is | ||
invalid. | ||
modify the given argument directly. That is why `delete` can be used on | ||
non-variables/documents, like in `(delete (read-config).password)` to get rid | ||
of individual keys from a larger data structure. To enable this, `delete` always | ||
returns the _remaining_ datastructure, not the value that was removed. | ||
|
||
To make your changes "stick", use the bang modifier: `(delete! $var.foo)` – this | ||
only makes sense for symbols (i.e. variables and the global document), since | ||
there is no "source" to be updated for e.g. literals (hence | ||
`(delete! [1 2 3][1])` is invalid). | ||
|
||
[`set`](set.md) is another function that is most often used with the bang | ||
modifier. | ||
modifier and also returns the entire datastructure, not just the newly inserted | ||
value. | ||
|
||
## Examples | ||
|
||
* `(delete! $var.key)` | ||
* `(delete! .[1])` | ||
|
||
<!-- This function is mostly used with the bang modifier, but can sometimes also be | ||
This function is mostly used with the bang modifier, but can sometimes also be | ||
useful without if you only want to modify an object/vector "in transit": | ||
|
||
* `(handle (delete (read-config).isAdmin))` to give `handle` a config object | ||
object without the `isAdmin` flag. --> | ||
* `(connect (delete (read-config).isAdmin))` to give `connect` a config object | ||
object without the `isAdmin` flag. | ||
|
||
## Forms | ||
|
||
### `(delete target:symbol)` ➜ `any` | ||
### `(delete target:pathed)` ➜ `any` | ||
|
||
* `target` is a symbol with a path expression. | ||
* `target` is a any expression with a path expression. | ||
|
||
`delete` evaluates the target expression and then removes whatever the path | ||
expression is pointing to. The return value is the remaining data (i.e. not the | ||
removed value). | ||
|
||
When used with the bang modifier, `target` must be a symbol with a path | ||
expression. | ||
|
||
## Context | ||
|
||
`delete` evaluates the expression in its own scope, so variables defined in it | ||
do not leak. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,44 @@ | ||
# delete | ||
|
||
`delete` removes a key from an object or an item from a vector (shrinking that | ||
vector by 1 element). | ||
|
||
<!-- It must be used with a path expression and can be used | ||
on expressions that support path expressions (e.g. `(delete (do-something).gone)`). --> | ||
vector by 1 element). It must be used on any expression that has a path | ||
expression attached (e.g. `(delete (do-something).gone)`). | ||
|
||
Note that `delete` is, like all functions in Rudi, stateless and so does not | ||
modify the given argument directly. To make your changes "stick", use the bang | ||
modifier: `(delete! $var.foo)` – this only makes sense for symbols (i.e. | ||
variables and the global document), which is incidentally also what the bang | ||
modifier itself already enforces. So an expression like `(delete! [1 2][1])` is | ||
invalid. | ||
modify the given argument directly. That is why `delete` can be used on | ||
non-variables/documents, like in `(delete (read-config).password)` to get rid | ||
of individual keys from a larger data structure. To enable this, `delete` always | ||
returns the _remaining_ datastructure, not the value that was removed. | ||
|
||
To make your changes "stick", use the bang modifier: `(delete! $var.foo)` – this | ||
only makes sense for symbols (i.e. variables and the global document), since | ||
there is no "source" to be updated for e.g. literals (hence | ||
`(delete! [1 2 3][1])` is invalid). | ||
|
||
[`set`](set.md) is another function that is most often used with the bang | ||
modifier. | ||
modifier and also returns the entire datastructure, not just the newly inserted | ||
value. | ||
|
||
## Examples | ||
|
||
* `(delete! $var.key)` | ||
* `(delete! .[1])` | ||
|
||
<!-- This function is mostly used with the bang modifier, but can sometimes also be | ||
This function is mostly used with the bang modifier, but can sometimes also be | ||
useful without if you only want to modify an object/vector "in transit": | ||
|
||
* `(handle (delete (read-config).isAdmin))` to give `handle` a config object | ||
object without the `isAdmin` flag. --> | ||
* `(connect (delete (read-config).isAdmin))` to give `connect` a config object | ||
object without the `isAdmin` flag. | ||
|
||
## Forms | ||
|
||
### `(delete target:symbol)` ➜ `any` | ||
### `(delete target:pathed)` ➜ `any` | ||
|
||
* `target` is a symbol with a path expression. | ||
* `target` is a any expression with a path expression. | ||
|
||
`delete` evaluates the target expression and then removes whatever the path | ||
expression is pointing to. The return value is the remaining data (i.e. not the | ||
removed value). | ||
|
||
When used with the bang modifier, `target` must be a symbol with a path | ||
expression. | ||
|
||
## Context | ||
|
||
`delete` evaluates the expression in its own scope, so variables defined in it | ||
do not leak. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.