IsCollection

Copied!
( value )

Description

The IsCollection function returns true only if value is a collection, otherwise it returns false.

Parameters

Parameter Type Definition and Requirements

value

Any

Any value, which is to be tested to determine whether it is a collection or not.

Returns

Returns a Boolean, indicating whether value was a collection or not.

Examples

The following query uses Map to iterate over an array of all of the types of values that can be tested by a type-check function, passing each item into a Lambda function that returns an object, which contains the value and the result of calling IsCollection with that value:

Copied!
client.query(
  q.(
    [
      ['array'],
      true,
      false,
      new Uint8Array([1, 2, 3, 4]),
      [0x1, 0x2, 0x3, 0x4],
      q.('Letters'),
      q.('credentials/self'),
      q.('child_db'),
      q.('2019-11-12'),
      q.(q.('Letters'), 123),
      10.1,
      q.('double'),
      q.('letters'),
      10,
      q.(q.(), '1'),
      q.(q.('x', q.('x'))),
      null,
      { x: 10 },
      q.('employees'),
      q.(q.('letters')),
      'ten',
      '10',
      q.('2020-07-06T12:34:56.789Z'),
      q.(q.(), '1'),
    ],
    q.('x', {
      value: q.('x'),
      IsCollection: q.(q.('x')),
    })
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
[
  { value: [ 'array' ], IsCollection: false },
  { value: true, IsCollection: false },
  { value: false, IsCollection: false },
  { value: Bytes("AQIDBA=="), IsCollection: false },
  { value: [ 1, 2, 3, 4 ], IsCollection: false },
  { value: ("Letters"), IsCollection: true },
  {
    value: ((), "268431923988136448"),
    IsCollection: false
  },
  { value: ("child_db"), IsCollection: false },
  { value: ("2019-11-12"), IsCollection: false },
  { value: (("Letters"), "123"), IsCollection: false },
  { value: 10.1, IsCollection: false },
  { value: ("double"), IsCollection: false },
  { value: ("letters"), IsCollection: false },
  { value: 10, IsCollection: false },
  { value: ((), "1"), IsCollection: false },
  { value: (("x", ("x"))), IsCollection: false },
  { value: null, IsCollection: false },
  { value: { x: 10 }, IsCollection: false },
  { value: ("employees"), IsCollection: false },
  { value: (("letters")), IsCollection: false },
  { value: 'ten', IsCollection: false },
  { value: '10', IsCollection: false },
  { value: ("2020-06-15T21:11:22.812Z"), IsCollection: false },
  { value: ((), "1"), IsCollection: false }
]
Query metrics:
  •    bytesIn:   608

  •   bytesOut: 1,679

  • computeOps:     2

  •    readOps:     0

  •   writeOps:     0

  •  readBytes:   373

  • writeBytes:     0

  •  queryTime:  29ms

  •    retries:     0

This query operates on a pre-existing schema, which is not provided here.

Also, the query is executed via a client connection, that uses a secret acquired by calling the Login function (not shown here), so that Ref("credentials/self") returns a valid value.

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!