-
Connecting
elements
toelements
via a pipe ought to "unwrap" two levels of arrays.> pipe elements elements (Array [Array [Number 1,Number 2], Array [Number 3,Number 4]]) [Number 1,Number 2,Number 3,Number 4]
-
Connecting
elements
tofield "a"
via a pipe takes everything from an array, and then all the"a"
fields.> pipe elements (field "a") (Array [Object [("a",Number 1)], Object [("a", Number 2)], Object []]) [Number 1, Number 2]
-
Connecting
field "a"
to elements via a pipe will look up the field"a"
in an object and then get all the elements from the array stored in that field.> pipe (field "a") elements (Object [("a", Array [Number 1, String "abc", Null])]) [Number 1, String "abc", Null]
-
Comparing constants that are equal:
> equal (int 1) (int 1) Null [Boolean True]
equal (int 1) (int 1)
should always give the same answer even if the input is notNull
. -
Comparing constants that are not equal:
> equal (int 1) (int 2) Null [Boolean False]
equal (int 1) (int 2)
should always give the same answer even if the input is notNull
. -
Comparing the elements of an array to a fixed integer:
> equal elements (int 1) (Array [Number 1, Number 2, Number 3, Number 4]) [Boolean True,Boolean False,Boolean False,Boolean False]
because
1
is equal to1
(the firstTrue
), but not equal to2
,3
, or4
. -
Comparing the elements of an array to itself compares all possible pairs:
> equal elements elements (Array [Number 1, Boolean True]) [Boolean True,Boolean False,Boolean False,Boolean True]
Spelled out, we are comparing all pairs:
Number 1
withNumber 1
, which is trueNumber 1
withBoolean True
, which is falseBoolean True
withNumber 1
, which is falseBoolean True
withBoolean True
, which is true
-
Comparing an element of an object with a fixed string:
> equal (field "a") (string "X") (Object [("a", String "X")]) [Boolean True]
-
Same again, but this time the field has a value which isn't
"X"
:> equal (field "a") (string "X") (Object [("a", String "Y")]) [Boolean False]
-
If the condition is always true, then you get back the input:
> select (equal (int 1) (int 1)) (Array [Number 1, Number 2]) [Array [Number 1, Number 2]]
-
If the condition is never true, then you get back the empty list:
> select (equal (int 1) (int 2)) (Array [Number 1, Number 2]) []
-
Selecting for the
"a"
field being1
, when it is:> select (equal (field "a") (int 1)) (Object [("a",Number 1)]) [Object [("a",Number 1)]]
-
Selecting for the
"a"
field being1
, when it isn't:> select (equal (field "a") (int 1)) (Object [("a",Number 2)]) []
-
If the
equal
returns multiple values, then only one of them needs to beTrue
for it to select that thing, so we can check to see if a certain element is in an array:ghci> select (equal elements (int 1)) (Array [Number 1, Number 3, Number 4]) [Array [Number 1,Number 3,Number 4]]
-
Same test, but this time with an array that doesn't contain
1
:> select (equal elements (int 1)) (Array [Number 3, Number 4]) []
-
Putting together
pipe
,equal
andselect
:> select (equal (pipe (field "a") elements) (int 1)) (Object [("a", Array [Number 1, String "abc", Null])]) [Object [("a",Array [Number 1,String "abc",Null])]]
and
> select (equal (pipe (field "a") elements) (int 1)) (Object [("a", Array [Number 2, String "abc", Null])]) []