diff --git a/JavaScript/6-functor-ap-fp.js b/JavaScript/6-functor-ap-fp.js index 5b2895a..45531e6 100644 --- a/JavaScript/6-functor-ap-fp.js +++ b/JavaScript/6-functor-ap-fp.js @@ -12,3 +12,24 @@ function maybe(x) { maybe(5)(x => x * 2)(x => ++x)(console.log); maybe(5)(x => x * 2).ap(maybe(x => ++x))(console.log); maybe(5).chain(x => maybe(x * 2))(x => ++x)(console.log); + +const config = { + coords: { + x: 0, + y: 5, + }, + velocity: { + x: 1, + y: 1, + }, +}; + +const addVelocity = velocity => coords => { + coords.x += velocity.x; + coords.y += velocity.y; + return coords; +}; + +const coords = maybe(config.coords); +const velocity = maybe(config.velocity); +coords.ap(velocity(addVelocity))(console.log);