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