source: node_modules/ramda-adjunct/src/internal/ap.js

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
Line 
1import { ap as apR, curryN, pathSatisfies, both, either } from 'ramda';
2
3import isFunction from '../isFunction';
4import * as fl from '../fantasy-land/mapping';
5
6const isFunctor = either(
7 pathSatisfies(isFunction, ['map']),
8 pathSatisfies(isFunction, [fl.map])
9);
10const isApply = both(
11 isFunctor,
12 either(pathSatisfies(isFunction, ['ap']), pathSatisfies(isFunction, [fl.ap]))
13);
14
15const 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
30export default ap;
Note: See TracBrowser for help on using the repository browser.