Require operator

The require operator filters the data stream to only include elements that contain the specified variables. Elements where any of the specified variables are unbound (empty) are removed from the stream.

Syntax

require <var> [ , <var> ... ];

Example

Schema for the following examples
#!test[schema, commit]
define
  entity content owns id;
  entity page sub content,
    owns page-id,
    owns name;
  entity profile sub page,
    owns username;
  entity user sub profile,
    owns phone,
    owns karma;

  attribute id value string;
  attribute page-id sub id;
  attribute username sub page-id;
  attribute name value string;
  attribute phone value string;
  attribute karma value double;
attribute bio value string;
attribute profile-picture value string;
attribute email @independent, value string @regex("^.*@.*\.com");
user owns bio, owns profile-picture, owns email;

Find users who have both a username and an email address:

#!test[read]
match
  $user isa user;
  try { $user has username $username; };
  try { $user has email $email; };
require $username, $email;

In this example, the try clauses make $username and $email optional. The require operator then filters the stream to only include users who have both attributes bound (note: in this example, it would have been equivalent to not use try clauses and skip the require clause!)