IsToken

Not available in this language yet.
IsToken( value )
IsToken( value )
IsToken( value )
is_token( value )
IsToken( value )

Description

The IsToken function returns true only if value is a token, otherwise it returns false.

Parameters

Argument Type Definition and Requirements

value

Any

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

Returns

Returns a boolean, indicating whether value was a token 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 IsToken with that value:

Not available in this language yet.
result, err := client.Query(
	f.Map(
		f.Arr{
			f.Arr{"array"},
			true,
			false,
			f.BytesV{0x01, 0x02, 0x03, 0x04},
			f.Arr{0x1, 0x2, 0x3, 0x4},
			f.Collection("Letters"),
			f.Ref("credentials/self"),
			f.Database("child_db"),
			f.Date("2019-11-12"),
			f.Ref(f.Collection("Letters"), 123),
			10.1,
			f.Function("double"),
			f.Index("letters"),
			10,
			f.Ref(f.Keys(), "1"),
			f.Query(f.Lambda("x", f.Var("x"))),
			nil,
			f.Null(),
			f.Obj{"x": 10},
			f.Role("employees"),
			f.Match(f.Index("letters")),
			"ten",
			"10",
			f.Time("2020-07-06T12:34:56.789Z"),
			f.Ref(f.Tokens(), "1"),
		},
		f.Lambda("x", f.Obj{
			"value": f.Var("x"),
			"IsToken": f.IsToken(f.Var("x")),
		})))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
[map[IsToken:false value:[array]] map[IsToken:false value:true] map[IsToken:false value:false] map[IsToken:false value:[1 2 3 4]] map[IsToken:false value:[1 2 3 4]] map[IsToken:false value:{Letters 0xc000122210 0xc000122210 <nil>}] map[IsToken:false value:{280481857410171392 0xc000122330 0xc000122330 <nil>}] map[IsToken:false value:{child_db 0xc000122450 0xc000122450 <nil>}] map[IsToken:false value:{0 63709113600 <nil>}] map[IsToken:false value:{123 0xc000122720 0xc000122720 <nil>}] map[IsToken:false value:10.1] map[IsToken:false value:{double 0xc000122870 0xc000122870 <nil>}] map[IsToken:false value:{letters 0xc000122990 0xc000122990 <nil>}] map[IsToken:false value:10] map[IsToken:false value:{1 0xc000122ae0 0xc000122ae0 <nil>}] map[IsToken:false value:{[123 34 97 112 105 95 118 101 114 115 105 111 110 34 58 34 51 34 44 34 108 97 109 98 100 97 34 58 34 120 34 44 34 101 120 112 114 34 58 123 34 118 97 114 34 58 34 120 34 125 125]}] map[IsToken:false value:{}] map[IsToken:false value:{}] map[IsToken:false value:map[x:10]] map[IsToken:false value:{employees 0xc000122cf0 0xc000122cf0 <nil>}] map[IsToken:false value:{map[match:{letters 0xc000122e40 0xc000122e40 <nil>}]}] map[IsToken:false value:ten] map[IsToken:false value:10] map[IsToken:false value:{789000000 63729635696 <nil>}] map[IsToken:true value:{1 0xc000122ff0 0xc000122ff0 <nil>}]]
System.out.println(
    client.query(
        Map(
            Arr(
                Arr(Value("array")),
                Value(true),
                Value(false),
                Value(new byte[] {0x1, 0x2, 0x3, 0x4}),
                Arr(Value(0x1), Value(0x2), Value(0x3), Value(0x4)),
                Collection("Letters"),
                Ref("credentials/self"),
                Database("child_db"),
                Date("2019-11-12"),
                Ref(Collection("Letters"), "123"),
                Value(10.1),
                Function("double"),
                Index("letters"),
                Value(10),
                Ref(Keys(), "1"),
                Query(Lambda("x", Var("x"))),
                Null(),
                Obj("x", Value(10)),
                Role("employees"),
                Match(Index("letters")),
                Value("ten"),
                Value("10"),
                Time("2020-07-06T12:34:56.789Z"),
                Ref(Tokens(), "1")
            ),
            Lambda(
                "x",
                Obj("value", Var("x"), "IsToken", IsToken(Var("x")))
            )
        )
    ).get());
[{value: ["array"], IsToken: false}, {value: true, IsToken: false}, {value: false, IsToken: false}, {value: [0x01 0x02 0x03 0x04], IsToken: false}, {value: [1, 2, 3, 4], IsToken: false}, {value: ref(id = "Letters", collection = ref(id = "collections")), IsToken: false}, {value: ref(id = "270598599674429952", collection = ref(id = "credentials")), IsToken: false}, {value: ref(id = "child_db", collection = ref(id = "databases")), IsToken: false}, {value: 2019-11-12, IsToken: false}, {value: ref(id = "123", collection = ref(id = "Letters", collection = ref(id = "collections"))), IsToken: false}, {value: 10.1, IsToken: false}, {value: ref(id = "double", collection = ref(id = "functions")), IsToken: false}, {value: ref(id = "letters", collection = ref(id = "indexes")), IsToken: false}, {value: 10, IsToken: false}, {value: ref(id = "1", collection = ref(id = "keys")), IsToken: false}, {value: QueryV({lambda=x, expr={var=x}}), IsToken: false}, {value: null, IsToken: false}, {value: {x: 10}, IsToken: false}, {value: ref(id = "employees", collection = ref(id = "roles")), IsToken: false}, {value: {@set = {match: ref(id = "letters", collection = ref(id = "indexes"))}}, IsToken: false}, {value: "ten", IsToken: false}, {value: "10", IsToken: false}, {value: 2020-07-06T12:34:56.789Z, IsToken: false}, {value: ref(id = "1", collection = ref(id = "tokens")), IsToken: true}]
client.query(
  q.Map(
    [
      ['array'],
      true,
      false,
      new Uint8Array([1, 2, 3, 4]),
      [0x1, 0x2, 0x3, 0x4],
      q.Collection('Letters'),
      q.Ref('credentials/self'),
      q.Database('child_db'),
      q.Date('2019-11-12'),
      q.Ref(q.Collection('Letters'), 123),
      10.1,
      q.Function('double'),
      q.Index('letters'),
      10,
      q.Ref(q.Keys(), '1'),
      q.Query(q.Lambda('x', q.Var('x'))),
      null,
      { x: 10 },
      q.Role('employees'),
      q.Match(q.Index('letters')),
      'ten',
      '10',
      q.Time('2020-07-06T12:34:56.789Z'),
      q.Ref(q.Tokens(), '1'),
    ],
    q.Lambda('x', {
      value: q.Var('x'),
      IsToken: q.IsToken(q.Var('x')),
    })
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
[
  { value: [ 'array' ], IsToken: false },
  { value: true, IsToken: false },
  { value: false, IsToken: false },
  { value: Bytes("AQIDBA=="), IsToken: false },
  { value: [ 1, 2, 3, 4 ], IsToken: false },
  { value: Collection("Letters"), IsToken: false },
  { value: Ref(Credentials(), "268286271391007232"), IsToken: false },
  { value: Database("child_db"), IsToken: false },
  { value: Date("2019-11-12"), IsToken: false },
  { value: Ref(Collection("Letters"), "123"), IsToken: false },
  { value: 10.1, IsToken: false },
  { value: Function("double"), IsToken: false },
  { value: Index("letters"), IsToken: false },
  { value: 10, IsToken: false },
  { value: Ref(Keys(), "1"), IsToken: false },
  { value: Query(Lambda("x", Var("x"))), IsToken: false },
  { value: null, IsToken: false },
  { value: { x: 10 }, IsToken: false },
  { value: Role("employees"), IsToken: false },
  { value: Match(Index("letters")), IsToken: false },
  { value: 'ten', IsToken: false },
  { value: '10', IsToken: false },
  { value: Time("2020-06-14T06:36:17.632Z"), IsToken: false },
  { value: Ref(Tokens(), "1"), IsToken: true }
]
result = client.query(
  q.map_(
    q.lambda_("x", {
      "value": q.var("x"),
      "IsToken": q.is_token(q.var("x")),
    }),
    [
      ["array"],
      True,
      False,
      bytearray([1, 2, 3, 4]),
      [0x1, 0x2, 0x3, 0x4],
      q.collection("Letters"),
      q.ref("credentials/self"),
      q.database("child_db"),
      q.date("2019-11-12"),
      q.ref(q.collection("Letters"), 123),
      10.1,
      q.function("double"),
      q.index("letters"),
      10,
      q.ref(q.keys(), "1"),
      q.query(q.lambda_("x", q.var("x"))),
      None,
      {"x": 10},
      q.role("employees"),
      q.match(q.index("letters")),
      "ten",
      "10",
      q.time("2020-07-06T12:34:56.789Z"),
      q.ref(q.tokens(), "1"),
    ],
  )
)
print(result)
[{'value': ['array'], 'IsToken': False}, {'value': True, 'IsToken': False}, {'value': False, 'IsToken': False}, {'value': bytearray(b'\x01\x02\x03\x04'), 'IsToken': False}, {'value': [1, 2, 3, 4], 'IsToken': False}, {'value': Ref(id=Letters, collection=Ref(id=collections)), 'IsToken': False}, {'value': Ref(id=282032258185953792, collection=Ref(id=credentials)), 'IsToken': False}, {'value': Ref(id=child_db, collection=Ref(id=databases)), 'IsToken': False}, {'value': datetime.date(2019, 11, 12), 'IsToken': False}, {'value': Ref(id=123, collection=Ref(id=Letters, collection=Ref(id=collections))), 'IsToken': False}, {'value': 10.1, 'IsToken': False}, {'value': Ref(id=double, collection=Ref(id=functions)), 'IsToken': False}, {'value': Ref(id=letters, collection=Ref(id=indexes)), 'IsToken': False}, {'value': 10, 'IsToken': False}, {'value': Ref(id=1, collection=Ref(id=keys)), 'IsToken': False}, {'value': Query({'api_version': '3', 'lambda': 'x', 'expr': {'var': 'x'}}), 'IsToken': False}, {'value': None, 'IsToken': False}, {'value': {'x': 10}, 'IsToken': False}, {'value': Ref(id=employees, collection=Ref(id=roles)), 'IsToken': False}, {'value': SetRef({'match': Ref(id=letters, collection=Ref(id=indexes))}), 'IsToken': False}, {'value': 'ten', 'IsToken': False}, {'value': '10', 'IsToken': False}, {'value': FaunaTime('2020-07-06T12:34:56.789Z'), 'IsToken': False}, {'value': Ref(id=1, collection=Ref(id=tokens)), 'IsToken': True}]
println(Await.result(
  client.query(
    Map(
      Arr(
        Arr("array"),
        true,
        false,
        BytesV(0x1, 0x2, 0x3, 0x4),
        Arr(0x1, 0x2, 0x3, 0x4),
        Collection("Letters"),
        Ref("credentials/self"),
        Database("child_db"),
        Date("2019-11-12"),
        Ref(Collection("Letters"), 123),
        10.1,
        Function("double"),
        Index("letters"),
        10,
        Ref(Keys(), "1"),
        Query(Lambda("x", Var("x"))),
        Null,
        Obj("x" -> 10),
        Role("employees"),
        Match(Index("letters")),
        "ten",
        "10",
        Time("2020-07-06T12:34:56.789Z"),
        Ref(Tokens(), "1")
      ),
      Lambda(
        "x",
        Obj( "value" -> Var("x"), "IsToken" -> IsToken(Var("x")))
      )
    )
  ),
  5.seconds
))
[{value: ["array"], IsToken: false}, {value: true, IsToken: false}, {value: false, IsToken: false}, {value: [0x01 0x02 0x03 0x04], IsToken: false}, {value: [1, 2, 3, 4], IsToken: false}, {value: ref(id = "Letters", collection = ref(id = "collections")), IsToken: false}, {value: ref(id = "270972905842541056", collection = ref(id = "credentials")), IsToken: false}, {value: ref(id = "child_db", collection = ref(id = "databases")), IsToken: false}, {value: 2019-11-12, IsToken: false}, {value: ref(id = "123", collection = ref(id = "Letters", collection = ref(id = "collections"))), IsToken: false}, {value: 10.1, IsToken: false}, {value: ref(id = "double", collection = ref(id = "functions")), IsToken: false}, {value: ref(id = "letters", collection = ref(id = "indexes")), IsToken: false}, {value: 10, IsToken: false}, {value: ref(id = "1", collection = ref(id = "keys")), IsToken: false}, {value: {api_version: "3", lambda: "x", expr: {var: "x"}}, IsToken: false}, {value: NullV, IsToken: false}, {value: {x: 10}, IsToken: false}, {value: ref(id = "employees", collection = ref(id = "roles")), IsToken: false}, {value: {@set = {match: ref(id = "letters", collection = ref(id = "indexes"))}}, IsToken: false}, {value: "ten", IsToken: false}, {value: "10", IsToken: false}, {value: 2020-07-06T12:34:56.789Z, IsToken: false}, {value: ref(id = "1", collection = ref(id = "tokens")), IsToken: true}]

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 Login (not shown here), so that Ref("credentials/self") returns a valid value.

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!