Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,8 @@
|
|||
def foo( filter ):
|
||||
("world" | filter) as $str
|
||||
| "hello \($str)" ;
|
||||
|
||||
# blue is defined here as a filter that adds blue to its input:
|
||||
def blue: "blue \(.)";
|
||||
|
||||
foo( blue ) # prints "hello blue world"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def g(f; x; y): [x,y] | f;
|
||||
|
||||
g(add; 2; 3) # => 5
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
def is_even:
|
||||
if floor == . then (. % 2) == 0
|
||||
else error("is_even expects its input to be an integer")
|
||||
end;
|
||||
26
Task/Higher-order-functions/Jq/higher-order-functions-4.jq
Normal file
26
Task/Higher-order-functions/Jq/higher-order-functions-4.jq
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Are all integers between 1 and 5 even?
|
||||
# For this example, we will use all/2 even
|
||||
# though it requires a release of jq after jq 1.4;
|
||||
# we do so to highlight the fact that all/2
|
||||
# terminates the generator once the condition is satisfied:
|
||||
all( range(1;6); is_even )
|
||||
false
|
||||
|
||||
# Display the even integers in the given range:
|
||||
range(1;6) | select(is_even)
|
||||
2
|
||||
4
|
||||
|
||||
# Evaluate is_even for each integer in an array
|
||||
[range(1;6)] | map(is_even)
|
||||
[false, true, false, true, false]
|
||||
|
||||
# Note that in jq, there is actually no need to call
|
||||
# a higher-order function in cases like this.
|
||||
# For example one can simply write:
|
||||
range(1;6) | is_even
|
||||
false
|
||||
true
|
||||
false
|
||||
true
|
||||
false
|
||||
Loading…
Add table
Add a link
Reference in a new issue