How to use the sanctuary-def.UnaryType function in sanctuary-def

To help you get started, we’ve selected a few sanctuary-def examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanctuary-js / sanctuary / test / internal / List.js View on Github external
List.prototype.constructor = List;

function _List(tag, head, tail) {
  this.isCons = tag === 'Cons';
  this.isNil = tag === 'Nil';
  if (this.isCons) {
    this.head = head;
    this.tail = tail;
  }
}

List['@@type'] = 'sanctuary/List';

//    Type :: Type -> Type
List.Type = $.UnaryType
  (List['@@type'])
  ('')
  ([])
  (x => type (x) === List['@@type'])
  (list => list);

//    Nil :: List a
const Nil = List.Nil = new _List ('Nil');

//    Cons :: a -> List a -> List a
const Cons = List.Cons = function Cons(head) {
  eq (arguments.length) (Cons.length);
  return function Cons$1(tail) {
    eq (arguments.length) (Cons$1.length);
    return new _List ('Cons', head, tail);
  };
github sanctuary-js / sanctuary / test / internal / sanctuary.js View on Github external
const UnaryType = name => typeIdent =>
  $.UnaryType (typeIdent)
              ('')
              ([])
              (x => type (x) === typeIdent)
              (v => [v.value])
              ($.Unknown);
github xodio / hm-def / test / signature.spec.js View on Github external
it ('should resolve maybes', () => {
    const Maybe = $.UnaryType
      ('my-package/Maybe')
      ('http://example.com/my-package#Maybe')
      (S.K (true))
      (S.K ([]));

    const env = $.env.concat ([
      Maybe ($.Unknown),
    ]);
    const {types} = resolve ($) ([]) (env) ('foo :: Maybe String -> String');
    assertTypePairs (S.zip (types) ([Maybe ($.String), $.String]));
  });
github xodio / hm-def / test / def.spec.js View on Github external
import {unchecked as S} from 'sanctuary';
import $ from 'sanctuary-def';
import Z from 'sanctuary-type-classes';
import {assert} from 'chai';
import {create} from '../src/index';

const hasProp = p => x => x[p] !== undefined;

const $Map = $.BinaryType
  ('Map')
  ('someurl')
  (S.is ($.Object))
  (S.keys)
  (S.values);

const $Wrapper = $.UnaryType
  ('Wrapper')
  ('someurl')
  (S.allPass ([S.is ($.Object), hasProp ('value')]))
  (S.pipe ([S.prop ('value'), S.of (Array)]));

const def = create ({
  $,
  checkTypes: true,
  env: $.env.concat ([
    $Map ($.Unknown) ($.Unknown),
    $Wrapper ($.Unknown),
  ]),
  typeClasses: [
    Z.Functor,
    Z.Semigroup,
  ],
github futurize / future-io / lib / types.js View on Github external
const $ = require('sanctuary-def')
const a = $.TypeVariable('a')
const b = $.TypeVariable('b')
const $IO = $.UnaryType(
  'future-io/IO',
  (x) => x && x['@@type'] === 'future-io/IO',
  () => []
)
const $Task = $.UnaryType(
  'Task',
  (x) => x && typeof x.fork === 'function',
  () => []
)
const env = $.env.concat([
  $IO,
  $Task
])
const def = $.create({ checkTypes: true, env })

module.exports = Object.assign({ def, a, b, $IO, $Task }, $)
github futurize / future-io / lib / types.js View on Github external
const $ = require('sanctuary-def')
const a = $.TypeVariable('a')
const b = $.TypeVariable('b')
const $IO = $.UnaryType(
  'future-io/IO',
  (x) => x && x['@@type'] === 'future-io/IO',
  () => []
)
const $Task = $.UnaryType(
  'Task',
  (x) => x && typeof x.fork === 'function',
  () => []
)
const env = $.env.concat([
  $IO,
  $Task
])
const def = $.create({ checkTypes: true, env })

module.exports = Object.assign({ def, a, b, $IO, $Task }, $)