-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #56
- Loading branch information
Showing
6 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import liftFN from './liftFN'; | ||
|
||
/** | ||
* "lifts" a function of arity > 1 so that it may "map over" objects that satisfy | ||
* the Apply spec of algebraic structures. This function is not compatible | ||
* with {@link https://github.com/fantasyland/fantasy-land#apply|FantasyLand Apply spec}. | ||
* | ||
* Lifting is specific for {@link https://github.com/scalaz/scalaz|scalaz} and {@link http://www.functionaljava.org/|functional java} implementations. | ||
* One of the mainstream libraries that uses this Apply spec is {@link https://cwmyers.github.io/monet.js/|monet.js}. | ||
* This function acts as interop for ramda and monet.js. | ||
* | ||
* More info {@link https://github.com/fantasyland/fantasy-land/issues/50|here}. | ||
* | ||
* @func liftF | ||
* @memberOf RA | ||
* @since {@link https://char0n.github.io/ramda-adjunct/1.2.0|v1.2.0} | ||
* @category Function | ||
* @sig Apply a => (a... -> a) -> (a... -> a) | ||
* @param {Function} fn The function to lift into higher context | ||
* @return {Function} The lifted function | ||
* @see {@link RA.liftFN|liftFN} | ||
* @example | ||
* | ||
* const { Maybe } = require('monet'); | ||
* | ||
* const add3 = (a, b, c) => a + b + c; | ||
* const madd3 = RA.liftF(add3); | ||
* | ||
* madd3(Maybe.Some(10), Maybe.Some(15), Maybe.Some(17)); //=> Maybe.Some(42) | ||
* madd3(Maybe.Some(10), Maybe.Nothing(), Maybe.Some(17)); //=> Maybe.Nothing() | ||
*/ | ||
const liftF = fn => liftFN(fn.length, fn); | ||
|
||
export default liftF; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Maybe } from 'monet'; | ||
import { curry } from 'ramda'; | ||
|
||
import RA from '../src/index'; | ||
import eq from './shared/eq'; | ||
|
||
const add3 = curry((a, b, c) => a + b + c); | ||
const add4 = curry((a, b, c, d) => a + b + c + d); | ||
const add5 = curry((a, b, c, d, e) => a + b + c + d + e); | ||
|
||
describe('liftF', function() { | ||
const addF3 = RA.liftF(add3); | ||
const addF4 = RA.liftF(add4); | ||
const addF5 = RA.liftF(add5); | ||
|
||
it('returns a function', function() { | ||
eq(typeof RA.liftF(add3), 'function'); | ||
}); | ||
|
||
it('can lift functions of any arity', function() { | ||
eq(addF3(Maybe.Some(1), Maybe.Some(1), Maybe.Some(1)), Maybe.Some(3)); | ||
eq(addF4(Maybe.Some(1), Maybe.Some(1), Maybe.Some(1), Maybe.Some(1)), Maybe.Some(4)); | ||
eq( | ||
addF5(Maybe.Some(1), Maybe.Some(1), Maybe.Some(1), Maybe.Some(1), Maybe.Some(1)), | ||
Maybe.Some(5) | ||
); | ||
}); | ||
}); |
File renamed without changes.