How to use sanctuary-type-classes - 10 common examples

To help you get started, we’ve selected a few sanctuary-type-classes 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 safareli / free / src / par.js View on Github external
map(f) {
    return ap(Par.of(f), this)
  },
  // :: Par f a ~> Par f (a -> b) -> Par f b
github safareli / free / src / par.js View on Github external
const argT = foldArg(argF, f, T)
      if (fns.length === 0) {
        return argT
      }
      let fn = fns.pop()
      let res = ap(fn.f, argT)

      if (fn.length > 1) {
        fns.push(Fn(res, fn.length - 1))
        continue
      }

      while (fns.length > 0) {
        fn = fns.pop()
        res = ap(fn.f, res)
        if (fn.length > 1) {
          fns.push(Fn(res, fn.length - 1))
          break
        }
      }

      if (fns.length === 0) {
        return res
      }
    }
  },
  // :: Par f a ~> (Ɐ x. f x -> g x) -> Par g a
github safareli / free / src / concurrent.js View on Github external
map(f) {
    return Seq(map(f, this.seq()))
  },
  // :: Concurrent f a ~> Concurrent f (a -> b) -> Concurrent f b
github safareli / free / src / seq.js View on Github external
const fn = stack.pop()
        focus = fn(focus.a)
      }
      if (Pure.is(focus)) {
        return of(T, done(focus.a))
      }
      while (Roll.is(focus)) {
        // We are mutating `stack` for performance reasons but it's not
        // an issue as it's not an observable side effects 8-)
        // If we wanted to do same in a staticly typed language,
        // some kind of efficient type aligned sequnce should be used.
        stack.push(focus.y)
        focus = focus.x
      }
      // here `focus` must be `Lift`
      return map((v) => {
        if (stack.length === 0) {
          return done(v)
        }
        const fn = stack.pop()
        const nextFocus = fn(v)
        return next({ focus: nextFocus, stack })
      }, f(focus.i))
    }, { focus: this, stack: [] })
  },
github safareli / free / src / seq.js View on Github external
return chainRec(T, (next, done, { focus, stack }) => {
      while (Pure.is(focus) && stack.length) {
        const fn = stack.pop()
        focus = fn(focus.a)
      }
      if (Pure.is(focus)) {
        return of(T, done(focus.a))
      }
      while (Roll.is(focus)) {
        // We are mutating `stack` for performance reasons but it's not
        // an issue as it's not an observable side effects 8-)
        // If we wanted to do same in a staticly typed language,
        // some kind of efficient type aligned sequnce should be used.
        stack.push(focus.y)
        focus = focus.x
      }
      // here `focus` must be `Lift`
      return map((v) => {
        if (stack.length === 0) {
          return done(v)
        }
        const fn = stack.pop()
        const nextFocus = fn(v)
github fluture-js / Fluture / test / unit / 5.par.js View on Github external
test('of resolves with the value', function (){
  var m = Z.of(Par, 1);
  return assertResolved(seq(m), 1);
});
github safareli / free / test / union.js View on Github external
test('misc', (t) => {
  const list = List.Cons(a, List.Nil)

  t.throws(() => { list.cata({ Cons: (a, b) => a }) }, 'throws if all cases are not handled')
  t.throws(() => { List.Cons(1) }, 'when creating a tagged type with to many arguments throws error')
  t.throws(() => { List.Cons(1, 1, 1) }, 'when creating a tagged type with to many arguments throws error')
  t.same(list.toString(), `List.Cons(${toString(a)}, List.Nil())`, 'toString on value should work')
  t.same(List.toString(), 'List', 'toString on type should work')
  t.same(List.Cons.toString(), 'List.Cons', 'toString on variant constructor should work')
  t.same(List.Nil.toString(), 'List.Nil()', 'toString on unit variant should work')
  t.same(list.x, a, 'when checking head value should return correct value')
  t.same(list.xs, List.Nil, 'when checking value value should return correct value')
  t.same(list.cata({
    Cons: (x, xs) => [x, xs],
    Nil: () => [],
  }), [list.x, list.xs], 'cata should work on Cons')
  t.same(List.Nil.cata({
    Cons: () => false,
    Nil: () => true,
  }), true, 'cata should work on Nil')
  t.same(List.is(list), true, '`is` on type works')
  t.same(List.is({}), false, '`is` on type works')
  t.same(List.Cons.is(list), true, '`is` on variant works')
github fluture-js / Fluture / test / util.js View on Github external
}, function (y){
      Z.equals(x, y) ? res() : rej(new AssertionError({
        expected: x,
        actual: y,
        message: 'Expected the Future to resolve with ' + show(x) + '; got: ' + show(y)
      }));
    });
  });
github fluture-js / Fluture / test / util.js View on Github external
export var eq = function eq (actual, expected){
  strictEqual(arguments.length, eq.length);
  strictEqual(show(actual), show(expected));
  strictEqual(Z.equals(actual, expected), true);
};
github Avaq / permissionary / test / index.js View on Github external
function eq(actual, expected) {
  assert.strictEqual (arguments.length, eq.length);
  assert.strictEqual (Z.toString (actual), Z.toString (expected));
  assert.strictEqual (Z.equals (actual, expected), true);
}