-
-
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.
Our version of only wraps original version of and adds backward compatibility layer with older versions of Monet (and possibly other monadic libraries) Closes #64
- Loading branch information
Showing
5 changed files
with
54 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import fl from 'fantasy-land'; | ||
import { ap as apR, curryN, pathSatisfies, both, anyPass } from 'ramda'; | ||
|
||
import isFunction from '../isFunction'; | ||
|
||
|
||
const isFunctor = anyPass([pathSatisfies(isFunction, ['map']), pathSatisfies(isFunction, [fl.map])]); | ||
const isApply = both( | ||
isFunctor, | ||
anyPass([pathSatisfies(isFunction, ['ap']), pathSatisfies(isFunction, [fl.ap])]) | ||
); | ||
|
||
|
||
const ap = curryN(2, (applyF, applyX) => { | ||
// return original ramda `ap` if not Apply spec | ||
if (!isApply(applyF) || !isApply(applyX)) { return apR(applyF, applyX) } | ||
|
||
try { | ||
// new version of `ap` starting from ramda version > 0.23.0 | ||
return applyF.ap(applyX); | ||
} catch (e) { | ||
// old version of `ap` till ramda version <= 0.23.0 | ||
return applyX.ap(applyF); | ||
} | ||
}); | ||
|
||
|
||
export default ap; |
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,23 @@ | ||
import { add, multiply } from 'ramda'; | ||
|
||
import eq from '../shared/eq'; | ||
import _ap from '../../src/internal/ap'; | ||
import Identity from '../../src/internal/fantasy-land/Identity'; | ||
|
||
|
||
describe('ap', function() { | ||
const m1 = Identity.of(1); | ||
const m2 = Identity.of(2).map(add); | ||
|
||
it('tests new fantasyland spec compatibility', function() { | ||
eq(_ap(m1, m2), Identity.of(3)); | ||
}); | ||
|
||
it('tests old fantasyland spec compatibility', function() { | ||
eq(_ap(m2, m1), Identity.of(3)); | ||
}); | ||
|
||
it('tests for non Apply spec', function() { | ||
eq(_ap([multiply(2), add(3)], [1, 2, 3]), [2, 4, 6, 4, 5, 6]); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--reporter mocha-multi-reporters | ||
--reporter-options configFile=test/mocha-multi.json | ||
--compilers babel-register | ||
test/*.js | ||
test/**/*.js |