Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monet.js<-> ramda lift interop #56

Closed
char0n opened this issue Apr 16, 2017 · 1 comment
Closed

Monet.js<-> ramda lift interop #56

char0n opened this issue Apr 16, 2017 · 1 comment
Assignees
Labels

Comments

@char0n
Copy link
Owner

char0n commented Apr 16, 2017

fantasyland/fantasy-land#50

const { Maybe } = require('monet');
const { curry, last, slice, reverse, reduce, pipe, ap, curryN, map, flip } = require('ramda');

const apF = flip(ap);

const liftFN = curry((arity, fn) => {
  const lifted = curryN(arity, fn);
  return curryN(arity, (...args) => {
    const accumulator = map(lifted, last(args));
    const apps = pipe(slice(0, -1), reverse)(args);
    return reduce(apF, accumulator, apps);
  });
});

const liftF = fn => liftFN(fn.length, fn);
const liftF2 = liftFN(2);
const liftF3 = liftFN(3);

const m2 = Maybe.of(2);
const m3 = Maybe.of(3);
const m4 = Maybe.of(4);
const add = liftF((a, b, c) => a + b + c);

console.dir(add(m2, m3, m4));
@char0n char0n added the feature label Apr 16, 2017
@char0n char0n self-assigned this Apr 16, 2017
@char0n char0n changed the title Monet.js lift interop Monet.js<-> ramda lift interop Apr 16, 2017
char0n added a commit that referenced this issue Apr 16, 2017
char0n added a commit that referenced this issue Apr 16, 2017
@char0n
Copy link
Owner Author

char0n commented Apr 16, 2017

Implemented.

@char0n char0n closed this as completed Apr 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant