Support De/Serialization & Functional Pipelines Like Elvish?
It should be possible for us to provide some builtin commands that can handle de/serialization of text, similar to what the Elvish shell is doing. No reason to let Elvish have an advantage over Ion! Could really use some insight from those who are more familiar with this sort of concept. This is my take on how we could achieve it.
Note that this could be an optional feature in order to keep the file size of Ion's binary small, if implementing this would increase file size too much.
Issue Dependencies
This would require builtin pipeline execution and associative arrays before it could be implemented.
- #246 (closed) : Associative Arrays
- #379 (closed) : Builtin Pipeline Execution
How It Might Work
- We could have builtin commands that can parse specific formats, such as
from-json
- Those commands would deserialize the format into our native associated array syntax
- We could also provide a
select
builtin which reads from stdin and has a SQL-ish syntax - And then an
each
builtin which also reads from stdin, and evaluates expressions with arguments supplied on each line fed to stdin. - ???
- Profit
Examples
Here's a JSON example:
{"colors": [
{ "name": "red", "value": "F00" },
{ "name": "blue", "value": "00F" },
]}
Example 1
$ wget <JSON_FILE> | from-json
&colors=[{&name='red' &value='FOO'} {&name='blue' &value='00F'}]
Example 2
wget <JSON_FILE> | from-json |
select all from colors
&name='red' &value='FOO'
&name='blue' &value='00F'
Example 3
wget <JSON_FILE> | from-json |
select all from colors |
each 'echo color={name} value={value}'
color=red value=F00
color=blue value=00F
Example 4
wget <JSON_FILE> | from-json |
select value from colors where name = red
$='FOO'
Example 5
wget <JSON_FILE> | from-json |
select name, value from colors where name = red
$='red' $='FOO'
Example 6
wget <JSON_FILE> | from-json |
select name, value from colors where name = red |
each 'echo color={0} value={1}'
color=red value=F00
Example 7
wget <JSON_FILE> | from-json |
select name, value from colors where name = red |
each 'echo color={name} value={value}'
color=red value=F00