moy-fp
Version:
A functional programming library.
23 lines (18 loc) • 533 B
JavaScript
import curry from '../Function/curry'
// simple internal Functor Identity
// you can also use external Identity to implement set, but it const more performance
const Identity = a => ({
value: a,
map(f){
return Identity(f(this.value))
},
})
// here we just use .value, and not use extract or Comonad, assue it has no side effects
/**
* Lens s a -> (a -> a) -> s -> s
* Lens s a = Functor f => (a -> f a) -> s -> f s
*/
const over = curry(
(Lens, fn, a) => Lens(x => Identity(fn(x)))(a).value
)
export default over