Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Last active July 31, 2016 03:05
Show Gist options
  • Save vlad-bezden/8b5852101da8a54590682a04858256ee to your computer and use it in GitHub Desktop.
Save vlad-bezden/8b5852101da8a54590682a04858256ee to your computer and use it in GitHub Desktop.
Alternation Curry Method

Alternation Curry Method

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.

License.

'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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment