Take

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

Take( num, array )
Take( num, array )
Take( num, array )
take( num, array )
Take( num, array )

Description

The Take function returns a new array of the same type as the array parameter that contains num elements from the head of the provided array. If num is zero or negative, the resulting array is empty.

When applied to a Page, the returned page’s "after" cursor is adjusted to only cover the taken elements. As special cases:

  • If num is negative, after is set to the same value as the original page’s "before".

  • If all elements from the original page were taken, after does not change.

Parameters

Parameter Type Definition and Requirements

array

Array or Page

Extract elements from this Array.

num

Integer

The Number of elements to extract from the beginning of array.

Returns

A new Array of the same type as array, containing the first num elements from array.

Examples

The following query creates a new array containing copies of the first two elements of the array’s argument:

try
{
    Value result = await client.Query(
        Take(2, Arr(1, 2, 3))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
Arr(LongV(1), LongV(2))
result, err := client.Query(
	f.Take(2, f.Arr{1, 2, 3}))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[1 2]
client.query(
  q.Take(2, [1, 2, 3])
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[ 1, 2 ]
result = client.query(
  q.take(2, [1, 2, 3])
)
print(result)
[ 1, 2 ]
Take(2, [1, 2, 3])
[ 1, 2 ]
Query metrics:
  •    bytesIn:  31

  •   bytesOut:  18

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 5ms

  •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!