First class environments: Difference between revisions
Content added Content deleted
(mv jq to its proper place alphabetically) |
(→{{header|jq}}: space vs time) |
||
Line 694: | Line 694: | ||
Finally, to present the results in tabular form, |
Finally, to present the results in tabular form, the following helper function will be useful: |
||
# Emit the last item in a stream |
|||
# or null if the stream is empty |
|||
def last(s): reduce s as $s (null; $s); |
|||
# Apply a filter to a stream, |
# Apply a filter to a stream, |
||
# and ALSO emit the last item in the stream filtered through "final" |
# and ALSO emit the last item in the stream filtered through "final" |
||
def filter_and_last(s; filter; final): |
def filter_and_last(s; filter; final): |
||
[s] as $array |
|||
| ($array[] | filter), ($array[-1] | final); |
|||