moy-fp
Version:
A functional programming library.
40 lines (33 loc) • 955 B
JavaScript
import __ from '../../src/Function/__'
import add from '../../src/Math/add'
/**
* Functor f => ((a, b, ..., m) -> n) -> ((f a, f b, ..., f m) -> f n)
*/
import lift from '../../src/Functor/lift'
import Identity from '../../src/Functor/Identity/index'
/**
* you should not use this similar funciton to get value anywhere in your application
* if you must need the inner value, you may need Comonad
* here is just simple for test
*/
const inspect = x => `Identity(${x.value})`
test('lift(not using __), array', () => {
expect(
lift(add)([1, 2])([3, 4])
).toEqual([4, 5, 5, 6])
})
test('lift(not using __), Identity', () => {
expect(
inspect(lift(add)(Identity.of(1))(Identity.of(2)))
).toEqual(inspect(Identity.of(3)))
})
test('lift(not using __), number', () => {
expect(
lift(add)(1)(2)
).toBeUndefined()
})
test('lift(using __), array', () => {
expect(
lift(add)(__, [3, 4])([1, 2])
).toEqual([4, 5, 5, 6])
})