UNPKG

moy-fp

Version:
33 lines (28 loc) 884 B
import __ from '../../src/Function/__' import Identity from '../../src/Functor/Identity/index' /** * (s -> a) -> ((a, s) -> s) -> Lens s a * Lens s a = Functor f => (a -> f a) -> s -> f s */ import lens from '../../src/Object/lens' /** * 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('lens(not using __), not execute', () => { expect( lens(a => a.x)((v, a) => a) ).toEqual(expect.any(Function)) }) test('lens(not using __), execute', () => { expect( inspect(lens(a => a.x)((v, a) => a)(Identity)({x: 1})) ).toBe('Identity({"x":1})') }) test('lens(using __), not execute', () => { expect( lens(__, (v, a) => a)(a => a.x) ).toEqual(expect.any(Function)) })