moy-fp
Version:
A functional programming library.
33 lines (28 loc) • 875 B
JavaScript
import __ from '../../src/Function/__'
import Identity from '../../src/Functor/Identity/index'
/**
* [k] -> Lens s a
* Lens s a = Functor f => (a -> f a) -> s -> f s
*/
import lensPath from '../../src/Object/lensPath'
/**
* 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(${JSON.stringify(x.value)})`
test('lensPath(not using __), not execute', () => {
expect(
lensPath(['a', 'x'])
).toEqual(expect.any(Function))
})
test('lensPath(not using __), execute', () => {
expect(
inspect(lensPath(['a', 'x'])(Identity)({a: {x: 1}}))
).toEqual('Identity({"a":{"x":1}})')
})
test('lensPath(using __), not execute', () => {
expect(
lensPath(__)(['a', 'x'])
).toEqual(expect.any(Function))
})