Example of Alternation Functional Method that uses curry. Also it provides example of how to use both lodash and lodash/fp
A Pen by Vlad Bezden on CodePen.
Example of Alternation Functional Method that uses curry. Also it provides example of how to use both lodash and lodash/fp
A Pen by Vlad Bezden on CodePen.
'use strict' | |
console.clear() | |
const fp = _.noConflict() | |
const alternation = fp.curry((func1, funct2, val) => func1(val) || funct2(val)) | |
const isEven = x => x % 2 === 0 | |
const isOdd = x => _.negate(isEven) | |
const print = x => console.log(x) | |
const evenMsg = x => { | |
if (isEven(x)) return 'even' | |
} | |
const oddMsg = x => { | |
if (isOdd(x)) return 'odd' | |
} | |
const alt = alternation(evenMsg, oddMsg) | |
console.log(_.times(10, x => alt(x))) |
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.1/lodash.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/lodash/4.14.1/lodash.fp.min.js"></script> |