moy-fp
Version:
A functional programming library.
32 lines (27 loc) • 832 B
JavaScript
import __ from '../../src/Function/__'
/**
* Functor f => (a -> f b) -> f a -> f b
*/
import chain from '../../src/Functor/chain'
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('chain(not using __), array', () => {
expect(
chain(x => [x, x + 1])([1, 2, 3])
).toEqual([1, 2, 2, 3, 3, 4])
})
test('chain(not using __), identity', () => {
expect(
inspect(chain(x => Identity.of(x + 1))(Identity.of(4)))
).toBe('Identity(5)')
})
test('chain(using __), identity', () => {
expect(
inspect(chain(__, Identity.of(4))(x => Identity.of(x + 1)))
).toBe('Identity(5)')
})