mirror of
https://github.com/wader/fq.git
synced 2024-12-26 15:02:28 +03:00
21 lines
386 B
Plaintext
21 lines
386 B
Plaintext
# Function using lambda argument. map from standard library:
|
|
def map(f): [.[] | f];
|
|
> [1,2,3] | map(. * 2)
|
|
[
|
|
2,
|
|
4,
|
|
6
|
|
]
|
|
# select from standard library:
|
|
def select(f): if f then . else empty end;
|
|
> [1,2,3] | map(select(. % 2 == 0))
|
|
[
|
|
2
|
|
]
|
|
|
|
# Function using argument binding and recursion to output multiple values
|
|
def down($n):
|
|
if $n >= 0 then $n, down($n-1)
|
|
else empty
|
|
end;
|