Map
( collection, lambda )
Map( collection, lambda )
Map( collection, lambda )
Map( collection, lambda )
map_expr( lambda, collection )
map collection lambda
Map( collection, lambda )
Map( collection, lambda )
Description
The Map
function applies a Lambda
serially to each member of the collection
and returns the results of
each application in a new collection of the same type. Later invocations
of the Lambda function can see the results of earlier invocations.
Parameters
Argument | Type | Definition and Requirements |
---|---|---|
|
Collection |
The target collection over which the |
|
The anonymous function to be executed. |
Examples
The query below has a Lambda which takes one variable "x" and adds 1 and then returns the value. This Lambda is executed once for each value in the collection. These values are 1, 2, 3.
curl https://db.fauna.com/ \
-u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
-d '{
"map": { "lambda": "x", "expr": { "add": [ { "var": "x" }, 1 ] } },
"collection": [ 1, 2, 3 ]
}'
client.Query(Map(Arr(1, 2, 3), x => Add(x, 1)));
System.out.println(
client.query(
Map(
Arr(Value(1), Value(2), Value(3)),
Lambda(Value("x"), Add(Var("x"), Value(1)))
)
).get());
result, _ := client.Query(
f.Map(f.Arr{1, 2, 3}, f.Lambda("x", f.Add(f.Var("x"), 1))),
)
fmt.Println(result)
client.query(Map(Arr(1, 2, 3), Lambda { x => Add(x, 1) }))
client.query(q.map_expr(lambda x: q.add(x, 1), [1, 2, 3]))
$client.query do
map [1, 2, 3] do |x|
add(x, 1)
end
end
client.query(
Map(collection: Arr(1, 2, 3), to: { x in Add(x, 1) })
)
client.query(
q.Map([1, 2, 3], q.Lambda("x", q.Add(q.Var("x"), 1))))
.then((ret) => console.log(ret));
HTTP/1.1 200 OK
{ "resource": [ 2, 3, 4 ] }
[ 2, 3, 4 ]
[2, 3, 4]
[2 3 4]
[ 2, 3, 4 ]
[ 2, 3, 4 ]
[ 2, 3, 4 ]
[ 2, 3, 4 ]
[ 2, 3, 4 ]
Was this article helpful?
We're sorry to hear that.
Tell us how we can improve!
documentation@fauna.com
Thank you for your feedback!