How to use the sanctuary.create function in sanctuary

To help you get started, we’ve selected a few sanctuary 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 mitodl / micromasters / static / js / lib / sanctuary.js View on Github external
// @flow
import R from "ramda"
import { create, env } from "sanctuary"

export const S = create({ checkTypes: false, env: env })

/*
 * returns Just(items) if all items are Just, else Nothing
 */
export const allJust = R.curry(
  (items: S.Maybe[]) => (R.all(S.isJust)(items) ? S.Just(items) : S.Nothing)
)

/*
 * converts a Maybe to a string
 */
export const mstr = S.maybe("", String)

/*
 * returns Nothing if the input is undefined|null,
 * else passes the input through a provided function
github zerobias / speak-r / app / util.js View on Github external
const tagvalue = (tag,mess)=>isof.Nil(mess) ? tag : [tag,mess].join(':  ')
const log = tag=>mess=>debug(tagvalue(tag,mess))
const pipelog = tag=>mess=>R.tap(log(tag)(mess))

const arrayify = R.pipe(R.defaultTo([]),R.unless(isof.Array,R.of))

// const P = (...pipes)=>R.apply(R.pipe,R.filter(isof.Func,pipes))


const isContainOrEq = P(arrayify,R.flip(R.contains))


const {create, env} = require('sanctuary')
const checkTypes = false//process.env.NODE_ENV !== 'production';
const S = create({checkTypes: checkTypes, env: env})

const prop = R.map(R.prop,{
  type: 'type',
  val:  'value',
  head: 'head',
  tail: 'tail',
  data: 'data'
})

const isString = isof.String

module.exports = {
  pipelog,log,isString,arrayify,P,isof,isContainOrEq,prop,RP,S
}
github fabioluz / fun-js / src / fun.js View on Github external
import Sanctuary from 'sanctuary';
import $ from 'sanctuary-def';
import Z from 'sanctuary-type-classes';
import Future from 'fluture';
import FutureTypes from 'fluture-sanctuary-types';

const S = Sanctuary.create ({
  checkTypes: process.env.NODE_ENV !== 'production',
  env: Sanctuary.env.concat (FutureTypes.env)
});

const def = $.create ({
  checkTypes: process.env.NODE_ENV !== 'production',
  env: $.env.concat (FutureTypes.env)
});

$.a = $.TypeVariable ('a');
$.b = $.TypeVariable ('b');
$.Either = S.EitherType;
$.Maybe = S.MaybeType;
$.Future = FutureTypes.FutureType;

// Extensions
github plaid / async-problem / common / sanctuary.js View on Github external
'use strict';

const FutureTypes   = require ('fluture-sanctuary-types');
const S             = require ('sanctuary');
const $             = require ('sanctuary-def');


//    PromiseType :: Type
const PromiseType = $.NullaryType
  ('Promise')
  ('')
  ([])
  (x => x != null && x.constructor === Promise);

module.exports = S.create ({
  checkTypes: true,
  env: S.env.concat (FutureTypes.env.concat ([PromiseType])),
});
github Huemul / chimi / src / sanctuary.js View on Github external
const optionalPropIsString = prop =>
  R.ifElse(R.has(prop), propIsString(prop), R.T)

const checkProps = R.allPass([
  propIsString('module'),
  optionalPropIsString('name'),
  optionalPropIsString('type'),
])

const isDepObject = R.both(isObject, checkProps)

const isDep = R.either(isString, isDepObject)

const chimiDependency = NullaryType('chimi/Dependency', '#', isDep)

const S = create({
  checkTypes: true,
  env: env.concat([chimiDependency]),
})

module.exports = S
github SodiumFRP / sodium-typescript / spec / FantasyLand.spec.ts View on Github external
/**
  * Fantasy-land Algebraic Data Type Compatability.
  * Cell satisfies the Monad and Comonad Categories (and hence Functor, Apply, Applicative, and Extend as well)
  * @see {@link https://github.com/fantasyland/fantasy-land} for more info
  * @see {@link https://github.com/sanctuary-js/sanctuary/blob/master/test/Maybe/Maybe.js} for valid test examples (Sanctuary's Maybe)
  */

const laws = require('fantasy-laws');
const { create, env } = require('sanctuary');
import * as jsc from 'jsverify';

import { Cell, StreamSink, Stream } from '../src/lib/Sodium';

const S = create({
  checkTypes: false,
  env,
});

describe('Fantasy-land Cell', () => {
  //would be nice if we could push all samples off to listeners... like in Fantasy-land Practical Tests below, but for unit testing it's okay

  function CellArb<a>(arb: jsc.Arbitrary</a><a>) {
    return arb.smap(x =&gt; new Cell</a><a>(x), x =&gt; x.sample());
  }

  function CellEq(a: Cell, b: Cell) {
    return a.sample() === b.sample();
  }

  function CellHead(x: string): Cell {</a>