Clause (js)


( API docs and the index table are auto-generated with clausejs-docgen.
To contribute to API notes & examples, make a pull request to annotation source files here.)

Introduction

Refer to README file for basic intro.

What is Conformation?

To put it plainly, as a developer you expect your data to be of certain "shape".

You define the shape of the data with clauses.

To "conform" your data with your clauses is to shape it in a way that is better organized, making it easier for your code to consume.

In order for conformation to work, one must specify a label for each part of your clause definition (example to follow below).

There are 3 ways that data can be conformed with Clause:

cat Conformation (on arrays and strings)
var MyCatClause = C.cat(
  'first', C.isStr, 
  'second', C.isNum, 
  'third', C.isBool
);
C.conform( MyCatClause, ["a", 2, true] )

In addition to arrays, strings can also be conformed with scat.

var StrClause = C.cat('greetings', C.zeroOrMore(C.scat('hello')),
                      'substence', C.zeroOrMore(C.scat('i am optional')),
                      'farewell', C.zeroOrMore(C.scat('bye')));

C.conform(StrClause, 'hellohellobyebyebyebye');
or Conformation
var MyOrClause = C.or('option1', C.isStr, 'option2', C.isNum );
C.conform( MyOrClause, 2 )
shape Conformation
var ShapeClause3 = C.shape( { 
  required: {
    abilityGroup: [ 
      // key expression
      (key) => key.indexOf('can') === 0,
      // value expression
      C.isBool
    ],
    someKey: C.isNatInt,
  }, 
  optional: ["somekey"],
  } );

C.conform( ShapeClause3, { 
  canDance: true, 
  canFly: true, 
  canSwim: false, 
  someKey: 999 
} )

Notice that for all the examples given above, a label is supplied for each conformed parts.

Regex-like Operations on Iterables

Both array and string are treated as iterables in Clause, which means both types can be the subject of regex-like operations.

For example, both of the following clause definitions are valid:

Array

var ArrayClause = C.cat('foos', C.oneOrMore(C.equal('foo')),
                        'bars', C.oneOrMore(C.equal('bar')));

C.conform(ArrayClause, ['foo', 'foo', 'foo', 'bar', 'bar']);

String

var StrClause = C.cat('foos', C.oneOrMore(C.scat('foo')),
                      'bars', C.oneOrMore(C.scat('bar')));

C.conform(StrClause, 'foofoofoobarbar');

Notice that in the first clause, we use C.equals() to treat the string as a single entity, whereas in the second, we use C.scat() to indicate that each character in the string is part of the collection that we run regex ops on.

Delayed & Namespaced Clauses

Delayed & namespaced clauses are useful when composing recursively defined clauses.

For example, suppose we want to write clause for binary trees. A binary tree node contains a left node and a right node, which in turn is also a binary tree node.

There are two ways to represent such structure with Clause.

Delayed Clause
var BinaryTreeClause = C.maybe( C.wall(
  C.cat(
    'nodeName', C.isStr, 
    'leftNode', C.delayed( () => BinaryTreeClause ),
    'rightNode', C.delayed( () => BinaryTreeClause )
  )
) );

C.isValid(
  BinaryTreeClause, 
  ['john', ['bob', ['alice', null, null], null], ['sam', null, ['jane', null, null]]]
);
Namespaced Clause

Alternatively, you may also use a namespaced clause to achieve the same effect by giving the tree node a global name in the registry:

C('myapp/BinaryTreeNode', C.maybe( C.wall(
  C.cat(
    'nodeName', C.isStr, 
    'leftNode', C( 'myapp/BinaryTreeNode' ),
    'rightNode', C( 'myapp/BinaryTreeNode' )
) ) ) );

C.isValid(
  C( 'myapp/BinaryTreeNode' ), 
  ['john', ['bob', ['alice', null, null], null], ['sam', null, ['jane', null, null]]]
);

Another added benefit for the second approach is that C( 'myapp/BinaryTreeNode' ) will be exposed as a global reference which you can use anywhere in your app.

API

Work in progress.

Below is a set of auto-generated API reference by clausejs-docgen based on clause declarations and their corrosponding annotations.

C
  function
Convenient method that combines C.get() and C.set() into one function to get or set clauses from the global registry.
Syntax
Examples
C("awesomeapp/TodoItem", TodoItemClause)
var ref = C("awesomeapp/TodoItem");
ref.get()
Clause Description
fclause( {
  <args>: or(
    "register", cat(
      "nsPath", NamespacePath, 
      "expression", Expression
    ), 
    "retrieve", cat( "nsPath", NamespacePath )
  ), 
  <ret>: or(
    Undefined, 
    ClauseReference
  )
} )
Argument Clause Graph

[or] either one of

Should be one of the following:

Option 1 “register”
Put the given expression onto the given path in the global clause registry.
Examples:
C("awesomeapp/TodoItem", TodoItemClause)
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “nsPath”
[clause]
A value of type clause.types/NamespacePath
Part 2 “expression”
[clause]
A value of type clause.types/Expression
Option 2 “retrieve”
Retrieves an expression from the given namespace path, or returns null if not found.
Examples:
C("awesomeapp/TodoItem")
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “nsPath”
[clause]
A value of type clause.types/NamespacePath
Return Value Clause Graph

[or] either one of

Should be one of the following:

Option 1
[clause]
A value of type clause.types/Undefined
Option 2
[clause]

clause.compose/


clause.compose.regex/


cat()
  function
Given a set of expressions or a set of label+expression pairs, returns a regex op that matches all values in an iterable. If labels are given, returns a map that groups values by these labels. Returns a Problem if no match is found.
Syntax
Examples
var CatClause = C.cat(C.isStr, C.isNum, C.isBool);
C.isValid( CatClause, ["a", 2, true] )
C.isValid( CatClause, ["a", false, "b"] )
var LabelledCatClause = C.cat(
  'first', C.isStr, 
  'second', C.isNum, 
  'third', C.isBool
);
C.conform( LabelledCatClause, ["a", 2, true] )
// equivalent to the above
var LabelledCatClause = C.cat([
  [ 'first', C.isStr ], 
  [ 'second', 'this is an optional comment on second', C.isNum ], 
  [ 'third', C.isBool ]
]);
C.conform( LabelledCatClause, ["a", 2, true] )
Clause Description
fclause( {
  <args>: and(
    cat(
      "expressions", or(
        "withLabels", or(
          zeroOrMore( cat(
            "name", ClauseLabel, 
            "comment", zeroOrOne( String ), 
            "expr", Expression
          ) ), 
          collOf( cat(
            "name", ClauseLabel, 
            "comment", zeroOrOne( String ), 
            "expr", Expression
          ) )
        ), 
        "withoutLabels", zeroOrMore( Expression )
      ), 
      "options", zeroOrOne( PlainObject )
    ), 
    noDupelicateLabels
  ), 
  <ret>: Clause
} )
Argument Clause Graph

[and]

Should satisfy all of the following expression:

Condition 1
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expressions”
[or] either one of

Should be one of the following:

Option 1 “withLabels”
[or] either one of

Should be one of the following:

Option 1
[*] zero or more
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “name”
[clause]
A value of type clause.types/ClauseLabel
Part 2 “comment”
[?] optional
[clause]
A value of type clause.types/String
Part 3 “expr”
[clause]
A value of type clause.types/Expression
Option 2
[collOf] a collection of
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “name”
[clause]
A value of type clause.types/ClauseLabel
Part 2 “comment”
[?] optional
[clause]
A value of type clause.types/String
Part 3 “expr”
[clause]
A value of type clause.types/Expression
Option 2 “withoutLabels”
[*] zero or more
[clause]
A value of type clause.types/Expression
Part 2 “options”
[?] optional
[clause]
A value of type clause.types/PlainObject
Condition 2
[pred] satisfies predicate
A value that satisfies " data-container="body" data-animation="false" data-delay="500"> noDupelicateLabels()
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
or()
  function
Given a set of expressions or a set of label+expression pairs, returns a regex op that matches a value with either one of the expressions. If labels are given, returns a map with a single key that indicates the matching label.
Syntax
Examples
var OrClause = C.or(C.isStr, C.isNum);
C.conform( OrClause, "a" )
var LabelledOrClause = C.or('option1', C.isStr, 'option2', C.isNum );
C.conform( LabelledOrClause, 2 )
// equivalent to the above
var LabelledOrClause = C.or([['option1', C.isStr], ['option2', C.isNum]] );
C.conform( LabelledOrClause, 2 )
Clause Description
fclause( {
  <args>: and(
    cat(
      "expressions", or(
        "withLabels", or(
          zeroOrMore( cat(
            "name", ClauseLabel, 
            "comment", zeroOrOne( String ), 
            "expr", Expression
          ) ), 
          collOf( cat(
            "name", ClauseLabel, 
            "comment", zeroOrOne( String ), 
            "expr", Expression
          ) )
        ), 
        "withoutLabels", zeroOrMore( Expression )
      ), 
      "options", zeroOrOne( PlainObject )
    ), 
    noDupelicateLabels
  ), 
  <ret>: Clause
} )
Argument Clause Graph

[and]

Should satisfy all of the following expression:

Condition 1
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expressions”
[or] either one of

Should be one of the following:

Option 1 “withLabels”
[or] either one of

Should be one of the following:

Option 1
[*] zero or more
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “name”
[clause]
A value of type clause.types/ClauseLabel
Part 2 “comment”
[?] optional
[clause]
A value of type clause.types/String
Part 3 “expr”
[clause]
A value of type clause.types/Expression
Option 2
[collOf] a collection of
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “name”
[clause]
A value of type clause.types/ClauseLabel
Part 2 “comment”
[?] optional
[clause]
A value of type clause.types/String
Part 3 “expr”
[clause]
A value of type clause.types/Expression
Option 2 “withoutLabels”
[*] zero or more
[clause]
A value of type clause.types/Expression
Part 2 “options”
[?] optional
[clause]
A value of type clause.types/PlainObject
Condition 2
[pred] satisfies predicate
A value that satisfies " data-container="body" data-animation="false" data-delay="500"> noDupelicateLabels()
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
zeroOrMore()
  function
Given a single expression, returns a regex op that matches zero or more values in an iterable. Returns a Problem if there are no matches.
Syntax
Examples
var ZOMClause = C.zeroOrMore(C.isNum);
C.isValid( ZOMClause, [1, 2, 3] )
C.isValid( ZOMClause, [1, 2, "3"] )
C.isValid( ZOMClause, [] )
var CombinedClause = C.cat( 
  "babbles", C.zeroOrMore(C.oneOf("foo", "bar", "baz")),
  "truths", C.zeroOrMore(C.isBool),
  "counts", C.zeroOrMore(C.isNatInt)
);
C.conform( CombinedClause, ["foo", "foo", "bar", true,  2, 3 , 4] )
C.isValid( CombinedClause, ["foo", "foo", "bar", 2, 3 , 4] )
C.isValid( CombinedClause, [ 2, 3 , 4 ] )
C.isValid( CombinedClause, [ ] )
Clause Description
fclause( {
  <args>: cat(
    "expr", Expression, 
    "opts", zeroOrOne( Object )
  ), 
  <ret>: Clause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expr”
[clause]
A value of type clause.types/Expression
Part 2 “opts”
[?] optional
[clause]
A value of type clause.types/Object
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
oneOrMore()
  function
Given a single expression, returns a regex op that matches one or more values in an iterable. Returns a Problem if there are no matches.
Syntax
Examples
var OOMClause = C.oneOrMore(C.equals("hello"));
C.isValid( OOMClause, [ "hello", "hello", "hello" ] )
C.isValid( OOMClause, [ "hello", "hello", "hello" ] )
var CombinedClause = C.cat( 
  "babbles", C.oneOrMore(C.oneOf("foo", "bar", "baz")),
  "truths", C.oneOrMore(C.isBool),
  "counts", C.oneOrMore(C.isNatInt)
);
C.conform( CombinedClause, ["foo", "foo", "baz", false, true, 2, 3 ] )
C.isValid( CombinedClause, [false, true, 2, 3 ] )
Clause Description
fclause( {
  <args>: cat(
    "expr", Expression, 
    "opts", zeroOrOne( Object )
  ), 
  <ret>: Clause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expr”
[clause]
A value of type clause.types/Expression
Part 2 “opts”
[?] optional
[clause]
A value of type clause.types/Object
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
zeroOrOne()
  function
Given a single expression, returns a regex op that matches zero or one values in an iterable. Returns a Problem if there are no matches.
Syntax
Examples
var ZOOClause = C.zeroOrOne( C.equals( "hello" ) );
C.isValid( ZOOClause, [ "hello" ] )
C.isValid( ZOOClause, [] )
var CombinedClause = C.cat( 
  "the babble", C.zeroOrOne( C.oneOf("foo", "bar", "baz") ),
  "the truth", C.zeroOrOne( C.isBool ),
  "the count", C.zeroOrOne( C.isNatInt )
);
C.conform( CombinedClause, ["foo", 4] )
Clause Description
fclause( {
  <args>: cat(
    "expr", Expression, 
    "opts", zeroOrOne( Object )
  ), 
  <ret>: Clause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expr”
[clause]
A value of type clause.types/Expression
Part 2 “opts”
[?] optional
[clause]
A value of type clause.types/Object
Return Value Clause Graph

[clause]
A value of type clause.types/Clause

clause.compose.string/


scat()
  function
Syntax
Examples
var StrClause = C.cat('greetings', C.zeroOrMore(C.scat('hello')),
                      'substence', C.zeroOrMore(C.scat('i am optional')),
                      'farewell', C.zeroOrMore(C.scat('bye')));

C.conform(StrClause, 'hellohellobyebyebyebye');
Clause Description
fclause( {
  <args>: cat( "string", String ), 
  <ret>: Clause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “string”
[clause]
A value of type clause.types/String
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
and()
  function
Given a list of expressions, returns a clause that matches a value with all the expressions. Successive conformed value propagates to the rest of the expressions.
Syntax
Examples
var AndClause = C.and( C.isStr, (s) => s.length > 5 );
C.isValid( AndClause, "abcdefgh" )
C.isValid( AndClause, "abc" )
var PropagatingAndClause = C.and( 
  C.cat( 
    "first", C.isStr, 
    "second", C.zeroOrMore( C.isNum )
  ),
  // "second" propagated from conformed results of the previous clause
  ({ second }) => second.length > 4 ) 
C.isValid( PropagatingAndClause, [ "foo", 2, 3, 4, 5, 6 ] )
C.conform( PropagatingAndClause, [ "foo", 2, 3, 4, 5, 6 ] )
C.isValid( PropagatingAndClause, [ "foo", 2, 3 ] )
Clause Description
fclause( {
  <args>: oneOrMore( Expression ), 
  <ret>: Clause
} )
Argument Clause Graph

[+] one or more
[clause]
A value of type clause.types/Expression
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
collOf()
  function
Given a single expression, returns a clause that matches all values in an iterable with the given expression.
Syntax
Examples
var CollOfStrClause = C.collOf(C.isStr);
C.conform( CollOfStrClause, ["a", "b", "c"] )
C.conform( CollOfStrClause, [] )
// notice the difference in behavior from C.zeroOrOne
var CombinedCollOfClause = C.cat( 
  "babbles", C.collOf(C.oneOf("foo", "bar", "baz")),
  "truths", C.collOf(C.isBool),
  "counts", C.collOf(C.isNatInt)
);
C.isValid( CombinedCollOfClause, [["foo", "foo", "bar"], [], [2, 3 , 4]] )
// invalid because collOf does not mix with regex ops like zeroOrMore
// collOf(...) here is equivalent to wall(zeroOrMore(...))
C.isValid( CombinedCollOfClause, ["foo", "foo", "bar", 2, 3 , 4] )
Clause Description
fclause( {
  <args>: cat(
    "expr", Expression, 
    "opts", zeroOrOne( Object )
  ), 
  <ret>: Clause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expr”
[clause]
A value of type clause.types/Expression
Part 2 “opts”
[?] optional
[clause]
A value of type clause.types/Object
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
mapOf()
  function
Given a pair of expressions, returns a clause that matches an object all of whose keys matches the first expression and all of whose values matches the second expression.
Syntax
Examples
var AbilityMapClause = C.mapOf(
      (key) => key.indexOf("can") === 0,
      C.isBool );
C.isValid( AbilityMapClause, { canFly: true, canSwim: true, canDance: false } )
C.isValid( AbilityMapClause, { canFly: true, canSwim: true, canDance: "huh?" } )
C.isValid( AbilityMapClause, { meNotValid: true, canSwim: true } )
Clause Description
fclause( {
  <args>: cat(
    "keyExpression", Expression, 
    "valExpression", Expression
  ), 
  <ret>: Clause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “keyExpression”
[clause]
A value of type clause.types/Expression
Part 2 “valExpression”
[clause]
A value of type clause.types/Expression
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
shape()
  function
Given an object with two optional properties "required" and "optional", returns a clause that matches an object all of whose keys matches the expressions defined in "required" object and some of whose values matches the expressions defined in "optional" objects.
Syntax
Examples
var ShapeClause = C.shape( { 
  required: ["key1", "key2", "key3"], 
  optional: ["key4"],
  } );
C.isValid( ShapeClause, { key1: true, key2: 2, key3: "ss", key4: false } )
C.isValid( ShapeClause, { key1: true, key2: 2, key3: "ss" } )
C.isValid( ShapeClause, { key1: true, key2: 2 } )
var ShapeClause2 = C.shape( { 
  required: {
    key1: C.isBool,
    key2: C.isNatInt,
  }, 
  optional: ["key5"],
  } );
C.isValid( ShapeClause2, { key1: true, key2: 2, key5: false } )
C.isValid( ShapeClause2, { key1: "not bool", key2: 2, key5: false } )
// key group conformation
var ShapeClause3 = C.shape( { 
  required: {
    abilityGroup: [ 
      // key expression
      (key) => key.indexOf('can') === 0,
      // value expression
      C.isBool
    ],
    someKey: C.isNatInt,
  }, 
  optional: ["key5"],
  } );
C.conform( ShapeClause3, { 
  canDance: true, 
  canFly: true, 
  canSwim: false, 
  someKey: 999 
} )
Clause Description
fclause( {
  <args>: cat( "shapeArgs", shape( {
    <optional>: {
      "requiredFields": {
        <key>: o,n,e,O,f,(,"req", "required",), 
        <val>: or(
          "keyList", zeroOrMore( isPropName ), 
          "fieldDefs", mapOf( {
            <key>: String, 
            <val>: or(
              "valExpressionOnly", Expression, 
              "keyValExprPair", cat(
                "keyExpression", Expression, 
                "valExpression", Expression
              )
            )
          } )
        )
      }, 
      "optionalFields": {
        <key>: o,n,e,O,f,(,"opt", "optional",), 
        <val>: or(
          "keyList", zeroOrMore( isPropName ), 
          "fieldDefs", mapOf( {
            <key>: String, 
            <val>: or(
              "valExpressionOnly", Expression, 
              "keyValExprPair", cat(
                "keyExpression", Expression, 
                "valExpression", Expression
              )
            )
          } )
        )
      }
    }
  } ) ), 
  <ret>: Clause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “shapeArgs”
[shape]
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
any()
  function
Returns a clause that matches any value.
Examples
C.isValid(C.any(), 123)
C.isValid(C.any(), true)
C.isValid(C.any(), ["sass"])
C.isValid(C.any(), null)
C.isValid(C.any(), undefined)
Clause Description
fclause( {
  <ret>: Clause
} )
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
wall()
  function
Given a single expression, returns a clause that does not regex-mix with the parent clause. Useful for validating a list inside another list in the sequence.
Syntax
Examples
var FreeMixClause = C.cat( C.oneOrMore( C.isNum ) );
C.isValid( FreeMixClause, [2, 3, 4] )
C.isValid( FreeMixClause, [ [2, 3, 4] ] )
var WalledClause = C.cat( C.wall( C.oneOrMore( C.isNum ) ) );;
C.isValid( WalledClause, [2, 3, 4] )
C.isValid( WalledClause, [ [2, 3, 4] ] )
Clause Description
fclause( {
  <args>: cat( Expression ), 
  <ret>: Expression
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1
[clause]
A value of type clause.types/Expression
Return Value Clause Graph

[clause]
A value of type clause.types/Expression
fclause()
  function
Given an object that contains "args", "ret" and "fn" expressions (all optionally), returns a clause whose instrument function takes a function and validates its arguments and return value during run time and whose instrumentConformed function takes a function that takes conformed arguments.
Syntax
Examples
// first, we define a cat clause
var FnArgsClause = C.zeroOrMore(
   C.cat(
     'name', C.isStr,
     'age', C.isNatInt,
     // optional field
     'isMember', C.zeroOrOne( C.isBool )
   )
 );
C.conform(FnArgsClause, ["john", 23, true, "mary", 25, "bob", 34])
// next, we define a fclause with args as the cat clause defined above
var MyFnSpec = C.fclause( {
 args: FnArgsClause,
 ret: C.isNatInt
} );

var nameCount = MyFnSpec.instrument( 
  function _nameCount() { return Array.from(arguments).filter((s) => C.isStr(s)).length; } 
);
nameCount("john", 23, true, "mary", 25, "bob", 34);
// invalid: missing name
    nameCount("john", 23, true, 24, false);
var averageAge = MyFnSpec.instrumentConformed( 
  function (cprofiles) { // "c" stands for "conformed"
    // cprofiles example:
    // [ { name: "john", age: 4, isMember: true }, { name: "mary", age: 23 }, { name: "bob", age: 102 } ]
    var sumOfAges = cprofiles
      .map( ( { age } ) => age )
      .reduce( (acc, c) => c + acc, 0 );
    return sumOfAges / cprofiles.length;
  }
);

// cprofile below conforms into 
averageAge("john", 4, true, "mary", 23, "bob", 102);
Clause Description
fclause( {
  <args>: cat( shape( {
    <optional>: {
      "args": Expression, 
      "ret": Expression, 
      "fn": fclause( {
        <args>: cat(
          "conformedArguments", any, 
          "conformedReturnValue", any
        ), 
        <ret>: any
      } )
    }
  } ) )
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1
[shape]
delayed()
  function
Given a funciton that returns a clause, returns a DelayedClause that does not evaluate until its get() function is called. Useful for constructing recursive clause definitions.
Syntax
Examples
var BinaryTreeClause = C.maybe( C.wall(
  C.cat(
    'nodeName', C.isStr, 
    'leftNode', C.delayed( () => BinaryTreeClause ),
    'rightNode', C.delayed( () => BinaryTreeClause )
  )
) );

C.isValid(
  BinaryTreeClause, 
  ['john', ['bob', ['alice', null, null], null], ['sam', null, ['jane', null, null]]]
);
Clause Description
fclause( {
  <args>: cat( "getFn", fclause( {
    <args>: cat(), 
    <ret>: Expression
  } ) ), 
  <ret>: DelayedClause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “getFn”
[fclause] a function
Syntax
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Return Value Clause Graph

[clause]
A value of type clause.types/Expression
Return Value Clause Graph

[clause]
A value of type clause.types/DelayedClause
nullable()
  function
Given an expression, returns a new clause that matches either the original clause or a null value.
Syntax
Examples
C.isValid(C.isStr, null);
C.isValid(C.nullable(C.isStr), null);
Clause Description
fclause( {
  <args>: cat( Expression ), 
  <ret>: Clause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1
[clause]
A value of type clause.types/Expression
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
undefinable()
  function
Given an expression, returns a new clause that matches either the original clause or undefined.
Syntax
Examples
C.isValid(C.isStr, undefined);
C.isValid(C.undefinable(C.isStr), undefined);
Clause Description
fclause( {
  <args>: cat( Expression ), 
  <ret>: Clause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1
[clause]
A value of type clause.types/Expression
Return Value Clause Graph

[clause]
A value of type clause.types/Clause
maybe()
  function
Given an expression, returns a new clause that matches either the original clause, a null value, or undefined.
Syntax
Examples
C.isValid(C.isObj, undefined);
C.isValid(C.maybe(C.isObj), null);
C.isValid(C.maybe(C.isObj), undefined);
Clause Description
fclause( {
  <args>: cat( Expression ), 
  <ret>: Clause
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1
[clause]
A value of type clause.types/Expression
Return Value Clause Graph

[clause]
A value of type clause.types/Clause

clause.utils/


enforce()
  function
Syntax
Clause Description
fclause( {
  <args>: cat(
    "expression", Expression, 
    "valueToCheck", any()
  ), 
  <ret>: Undefined
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expression”
[clause]
A value of type clause.types/Expression
Part 2 “valueToCheck”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Undefined
conform()
  function
Syntax
Clause Description
fclause( {
  <args>: cat(
    "expression", Expression, 
    "valueToConform", any()
  ), 
  <ret>: or(
    "conformedValue", any(), 
    "problem", Problem
  )
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expression”
[clause]
A value of type clause.types/Expression
Part 2 “valueToConform”
[any]
Any value.
Return Value Clause Graph

[or] either one of

Should be one of the following:

Option 1 “conformedValue”
[any]
Any value.
Option 2 “problem”
[pred] satisfies predicate
A value of type clause.types/Problem
describe()
  function
Returns an abbreviated description of the clause as a simple tree structure.
Syntax
Clause Description
fclause( {
  <args>: cat(
    "expression", Expression, 
    "replacer", zeroOrOne( fclause( {
      <args>: cat( Expression ), 
      <ret>: or(
        Undefined, 
        Null, 
        collOf( String )
      )
    } ) ), 
    "space", zeroOrOne( isNatInt )
  ), 
  <ret>: String
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expression”
[or] either one of
A value of type clause.types/Expression
Part 2 “replacer”
[?] optional
[fclause] a function
Syntax
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1
[clause]
A value of type clause.types/Expression
Return Value Clause Graph

[or] either one of

Should be one of the following:

Option 1
[clause]
A value of type clause.types/Undefined
Option 2
[clause]
A value of type clause.types/Null
Option 3
[collOf] a collection of
[clause]
A value of type clause.types/String
Part 3 “space”
[?] optional
[pred] satisfies predicate
A value that satisfies isNatInt()
Return Value Clause Graph

[clause]
A value of type clause.types/String
sExpression()
  function
Syntax
Clause Description
fclause( {
  <args>: cat( "expression", Expression ), 
  <ret>: SExpression
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expression”
[or] either one of
A value of type clause.types/Expression
Return Value Clause Graph

[clause]
A value of type clause.types/SExpression
match()
  function
Syntax
  • ( keyValMap: Object, handlers: < String, ( any ) → any > ) → any
Clause Description
fclause( {
  <args>: cat(
    "keyValMap", Object, 
    "handlers", mapOf( {
      <key>: String, 
      <val>: fclause( {
        <args>: cat( "val", any ), 
        <ret>: any
      } )
    } )
  )
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “keyValMap”
[clause]
A value of type clause.types/Object
Part 2 “handlers”
[map_of]
isProblem()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool

clause.preds/


not()
  function
Syntax
Clause Description
fclause( {
  <args>: cat( "predicateToNegate", Predicate ), 
  <ret>: fclause( {
    <args>: cat( "x", any() ), 
    <ret>: Bool
  } )
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “predicateToNegate”
[fclause] a function
A value of type clause.types/Predicate
Return Value Clause Graph

[fclause] a function
Syntax
  • ( x: any ) → Bool
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isObj()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isPlainObj()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isStr()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isArray()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isDate()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isNull()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isUndefined()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
notEmpty()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isBool()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isFn()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isNum()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isInt()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isNatInt()
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
isUuid()
  function
Syntax
Clause Description
fclause( {
  <args>: cat( "x", String ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[clause]
A value of type clause.types/String
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
oneOf()
  function
Syntax
Clause Description
fclause( {
  <args>: cat( "valueOptions", collOf( Primitive ) ), 
  <ret>: fclause( {
    <args>: cat( "x", any() ), 
    <ret>: Bool
  } )
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “valueOptions”
[collOf] a collection of
[or] either one of
A value of type clause.types/Primitive
Return Value Clause Graph

[fclause] a function
Syntax
  • ( x: any ) → Bool
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
equals()
  function
Syntax
  • ( valueToCompareWith: any ) → ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "valueToCompareWith", any() ), 
  <ret>: fclause( {
    <args>: cat( "x", any() ), 
    <ret>: Bool
  } )
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “valueToCompareWith”
[any]
Any value.
Return Value Clause Graph

[fclause] a function
Syntax
  • ( x: any ) → Bool
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
instanceOf()
  function
Syntax
  • ( isFunction ) → ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "instanceType", isFunction ), 
  <ret>: fclause( {
    <args>: cat( "x", any() ), 
    <ret>: Bool
  } )
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “instanceType”
[pred] satisfies predicate
A value that satisfies isFunction()
Return Value Clause Graph

[fclause] a function
Syntax
  • ( x: any ) → Bool
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool

clause.namespace/


set()
  function
Registers a clause in to global clause registry.
Syntax
Examples
C("awesomeapp/TodoItem", TodoItemClause)
Clause Description
fclause( {
  <args>: cat(
    "nsPath", NamespacePath, 
    "expression", Expression
  ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “nsPath”
[clause]
A value of type clause.types/NamespacePath
Part 2 “expression”
[clause]
A value of type clause.types/Expression
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
get()
  function
Gets a clause reference from global clause registry.
Syntax
Examples
C("awesomeapp/TodoItem")
C("awesomeapp/TodoItem").get()
Clause Description
fclause( {
  <args>: cat( "nsPath", NamespacePath ), 
  <ret>: ClauseReference
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “nsPath”
[clause]
A value of type clause.types/NamespacePath
Return Value Clause Graph

[clause]
resolve()
  function
Syntax
Clause Description
fclause( {
  <args>: cat(
    "expression", Expression, 
    "registry", zeroOrOne( Object )
  ), 
  <ret>: NamespacePath
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “expression”
[clause]
A value of type clause.types/Expression
Part 2 “registry”
[?] optional
[clause]
A value of type clause.types/Object
Return Value Clause Graph

[clause]
A value of type clause.types/NamespacePath
setMeta()
  function
Syntax
Clause Description
fclause( {
  <args>: cat(
    "source", or(
      "namespacePath", NamespacePath, 
      "expression", Expression
    ), 
    "metaObj", Object, 
    "registry", zeroOrOne( Object )
  ), 
  <ret>: Undefined
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “source”
[or] either one of

Should be one of the following:

Option 1 “namespacePath”
[clause]
A value of type clause.types/NamespacePath
Option 2 “expression”
[clause]
A value of type clause.types/Expression
Part 2 “metaObj”
[clause]
A value of type clause.types/Object
Part 3 “registry”
[?] optional
[clause]
A value of type clause.types/Object
Return Value Clause Graph

[clause]
A value of type clause.types/Undefined
getMeta()
  function
Syntax
Clause Description
fclause( {
  <args>: cat(
    "source", or(
      "namespacePath", NamespacePath, 
      "expression", Expression
    ), 
    "registry", zeroOrOne( Object )
  ), 
  <ret>: or(
    Null, 
    Undefined, 
    Object
  )
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “source”
[or] either one of

Should be one of the following:

Option 1 “namespacePath”
[clause]
A value of type clause.types/NamespacePath
Option 2 “expression”
[clause]
A value of type clause.types/Expression
Part 2 “registry”
[?] optional
[clause]
A value of type clause.types/Object
Return Value Clause Graph

[or] either one of

Should be one of the following:

Option 1
[clause]
A value of type clause.types/Null
Option 2
[clause]
A value of type clause.types/Undefined
Option 3
[clause]
A value of type clause.types/Object

clause.types/


Expression
  or

Should be one of the following:

Option 1 “clause”
[clause]
A value of type clause.types/Clause
Option 2 “pred”
[pred] satisfies predicate
A value that satisfies isPred()
Clause
  predicate
A value that satisfies instanceOf_Clause()
Problem
  predicate
A value that satisfies isProblem()
FClause
  predicate
A value that satisfies isFclause()
Predicate
  function
Syntax
  • ( x: any ) → Bool
Clause Description
fclause( {
  <args>: cat( "x", any() ), 
  <ret>: Bool
} )
Argument Clause Graph

[cat] a sequence of

Should be an ordered list of the following:

Part 1 “x”
[any]
Any value.
Return Value Clause Graph

[clause]
A value of type clause.types/Bool
DelayedClause
  predicate
A value that satisfies instanceOf_DelayedClause()
ClauseReference
  predicate
A value that satisfies isClauseRef()
NamespaceObj
  shape
NamespacePath
  predicate
A value that satisfies isNamespacePath()
ClauseLabel
  predicate
A value that satisfies isClauseName()
SExpression
  wall
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “head”
[clause]
A value of type clause.types/Expression
Part 2 “params”
[or] either one of

Should be one of the following:

Option 1 “labelled”
[*] zero or more
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “label”
[or] either one of

Should be one of the following:

Option 1 “str”
[clause]
A value of type clause.types/String
Option 2 “quoted”
[pred] satisfies predicate
A value that satisfies instanceOf_Quoted()
Part 2 “item”
[or] either one of

Should be one of the following:

Option 1 “sExpression”
[clause]
A value of type clause.types/SExpression
Option 2 “quotedParamsMap”
[and]

Should satisfy all of the following expression:

Condition 1
[pred] satisfies predicate
A value that satisfies instanceOf_QuotedParamsMap()
Condition 2
[map_of]
Option 3 “unquotedParamsMap”
[and]

Should satisfy all of the following expression:

Condition 1
[pred] satisfies predicate
A value that satisfies instanceOf_UnquotedParamsMap()
Condition 2
[map_of]
Option 4 “optionsObj”
[clause]
A value of type clause.types/PlainObject
Option 5 “recursive”
[pred] satisfies predicate
A value that satisfies instanceOf_Recursive()
Option 2 “unlabelled”
[*] zero or more
[cat] a sequence of

Should be an ordered list of the following:

Part 1 “item”
[or] either one of

Should be one of the following:

Option 1 “sExpression”
[clause]
A value of type clause.types/SExpression
Option 2 “quotedParamsMap”
[and]

Should satisfy all of the following expression:

Condition 1
[pred] satisfies predicate
A value that satisfies instanceOf_QuotedParamsMap()
Condition 2
[map_of]
Option 3 “unquotedParamsMap”
[and]

Should satisfy all of the following expression:

Condition 1
[pred] satisfies predicate
A value that satisfies instanceOf_UnquotedParamsMap()
Condition 2
[map_of]
Option 4 “optionsObj”
[clause]
A value of type clause.types/PlainObject
Option 5 “recursive”
[pred] satisfies predicate
A value that satisfies instanceOf_Recursive()
Primitive
  or

Should be one of the following:

Option 1
[clause]
A value of type clause.types/String
Option 2
[clause]
A value of type clause.types/Number
Option 3
[clause]
A value of type clause.types/Bool
Option 4
[clause]
A value of type clause.types/Null
Option 5
[clause]
A value of type clause.types/Undefined
String
  predicate
A value that satisfies isString()
Bool
  predicate
A value that satisfies isBool()
Number
  predicate
A value that satisfies isNum()
Object
  predicate
A value that satisfies isObject()
PlainObject
  predicate
A value that satisfies isPlainObject()
Undefined
  predicate
A value that satisfies isUndefined()
Null
  predicate
A value that satisfies isNull()