main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
793 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | import { ap as apR, curryN, pathSatisfies, both, either } from 'ramda';
|
---|
| 2 |
|
---|
| 3 | import isFunction from '../isFunction';
|
---|
| 4 | import * as fl from '../fantasy-land/mapping';
|
---|
| 5 |
|
---|
| 6 | const isFunctor = either(
|
---|
| 7 | pathSatisfies(isFunction, ['map']),
|
---|
| 8 | pathSatisfies(isFunction, [fl.map])
|
---|
| 9 | );
|
---|
| 10 | const isApply = both(
|
---|
| 11 | isFunctor,
|
---|
| 12 | either(pathSatisfies(isFunction, ['ap']), pathSatisfies(isFunction, [fl.ap]))
|
---|
| 13 | );
|
---|
| 14 |
|
---|
| 15 | const ap = curryN(2, (applyF, applyX) => {
|
---|
| 16 | // return original ramda `ap` if not Apply spec
|
---|
| 17 | if (!isApply(applyF) || !isApply(applyX)) {
|
---|
| 18 | return apR(applyF, applyX);
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | try {
|
---|
| 22 | // new version of `ap` starting from ramda version > 0.23.0
|
---|
| 23 | return applyF.ap(applyX);
|
---|
| 24 | } catch (e) {
|
---|
| 25 | // old version of `ap` till ramda version <= 0.23.0
|
---|
| 26 | return applyX.ap(applyF);
|
---|
| 27 | }
|
---|
| 28 | });
|
---|
| 29 |
|
---|
| 30 | export default ap;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.