How to use the sanctuary-def.Object 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 node-gh / gh / src / fp.ts View on Github external
return S.isJust(result) ? S.Right(result.value) : S.Left(null)
    }
}

/**
 * Concats two strings
 * @return {Future}
 */
export const prepend = (a: string) => (b: string) => {
    const argsAreStrings = typeof a === 'string' && typeof b === 'string'

    return argsAreStrings ? Future.of(a + b) : Future.reject('Both args should be strings')
}

/* TYPE CHECKING UTILS */
export const isObject = S.is($.Object)

/* LOGGING UTILS */
export const l = x => {
    console.log('!!!!!!!', x)
    return x
}

// returns a future
export const lf = x => {
    console.log('-------', x)
    return Future.of(x)
}
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),
  ]),
github xodio / hm-def / test / def.spec.js View on Github external
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,
  ],
});

describe ('def', () => {
github sanctuary-js / sanctuary / test / gets.js View on Github external
test ('gets', () => {

  eq (S.show (S.gets)) ('gets :: (Any -> Boolean) -> Array String -> a -> Maybe b');

  eq (S.gets (S.is ($.Number)) (['x']) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Number)) (['y']) ({x: {z: 0}, y: 42})) (S.Just (42));
  eq (S.gets (S.is ($.Number)) (['z']) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Number)) (['x', 'z']) ({x: {z: 0}, y: 42})) (S.Just (0));
  eq (S.gets (S.is ($.Number)) (['a', 'b', 'c']) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Number)) ([]) ({x: {z: 0}, y: 42})) (S.Nothing);
  eq (S.gets (S.is ($.Object)) ([]) ({x: {z: 0}, y: 42})) (S.Just ({x: {z: 0}, y: 42}));
  eq (S.gets (S.is ($.RegExp)) (['x']) ({x: vm.runInNewContext ('/.*/')})) (S.Just (/.*/));

  eq (S.gets (S.K (true)) (['valueOf']) (null)) (S.Nothing);
  eq (S.gets (S.K (true)) (['valueOf']) (undefined)) (S.Nothing);

  eq (S.gets (S.is ($.Array ($.Number))) (['x']) ({x: [1, 2]})) (S.Just ([1, 2]));
  eq (S.gets (S.is ($.Array ($.Number))) (['x']) ({x: [1, 2, null]})) (S.Nothing);

});
github fabioluz / fun-js / src / common / types / env.js View on Github external
import $ from 'sanctuary-def';

export const $Env = $.RecordType ({ 
  repositories: $.Object
});
github xodio / hm-def / src / index.js View on Github external
import $priv from 'sanctuary-def';
import * as Sig from './signature';

const def = $priv.create ({checkTypes: true, env: $priv.env});

const Parameters = $priv.RecordType ({
  $: $priv.Object,
  checkTypes: $priv.Boolean,
  env: $priv.Array ($priv.Type),
  typeClasses: $priv.Array ($priv.TypeClass),
});

export const create = def
  ('create')
  ({})
  ([
    Parameters,
    $priv.String,
    $priv.AnyFunction,
    $priv.AnyFunction,
  ])
  (({$, checkTypes, env, typeClasses}) => {
    const $def = $.create ({checkTypes, env});