diff --git a/README.md b/README.md index 21f4e68..a5e2f6a 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,12 @@ as a guide, making sure your own implementation behaves as expected. ## Functionality - [Box](#box) -- LazyBox +- [LazyBox](#lazybox) - composeLeft - composeRight - pipeLeft - pipeRight -## Functional concepts ### Box A Box takes a value and boxes it up. On the box you'll be able to use a minimal, Box-specific API which does not care about the value inside the Box. The API is as follows: @@ -45,4 +44,16 @@ export const Box = (value) => ({ The Box above is just the simplest form of the concept. Based on what you want to put in and/or want to get back out of it, the implementation differs. Some examples of Boxes are: Left, Right, -Maybe, Nothing, LazyBox, ... +Maybe, Nothing, [LazyBox](#lazybox), ... + +### LazyBox +Does the same as [Box](#box) but does it to a function instead of a value. The function passed to +the LazyBox will not be executed while mapping over it. Only when you fold the LazyBox, the chained +functionality will be executed. + +```javascript +export const LazyBox = g => ({ + map: f => LazyBox(() => f(g())), + fold: (f = x => x) => f(g()) +}); +``` diff --git a/dist/cjs/subterfuge.js b/dist/cjs/subterfuge.js index ed86849..bd9ad9d 100644 --- a/dist/cjs/subterfuge.js +++ b/dist/cjs/subterfuge.js @@ -28,16 +28,16 @@ const Box = value => ({ /** * LazyBox takes a function and 'boxes' it up. * - * @param func1 + * @param g * * LazyBox.map: takes a function parameter, returns a new LazyBox containing a function that composes the parameter with the boxed function. * LazyBox.fold: takes a function parameter, composes the parameter with the boxed function and returns the result. * LazyBox.inspect: returns a string-template showing the Boxed up value. */ -const LazyBox = func1 => ({ - map: func2 => LazyBox(() => func2(func1())), - fold: (func2 = x => x) => func2(func1()) +const LazyBox = g => ({ + map: f => LazyBox(() => f(g())), + fold: (f = x => x) => f(g()) }); /** diff --git a/dist/es/subterfuge.js b/dist/es/subterfuge.js index 86fc10f..7e2ac98 100644 --- a/dist/es/subterfuge.js +++ b/dist/es/subterfuge.js @@ -24,16 +24,16 @@ const Box = value => ({ /** * LazyBox takes a function and 'boxes' it up. * - * @param func1 + * @param g * * LazyBox.map: takes a function parameter, returns a new LazyBox containing a function that composes the parameter with the boxed function. * LazyBox.fold: takes a function parameter, composes the parameter with the boxed function and returns the result. * LazyBox.inspect: returns a string-template showing the Boxed up value. */ -const LazyBox = func1 => ({ - map: func2 => LazyBox(() => func2(func1())), - fold: (func2 = x => x) => func2(func1()) +const LazyBox = g => ({ + map: f => LazyBox(() => f(g())), + fold: (f = x => x) => f(g()) }); /** diff --git a/src/lazybox.js b/src/lazybox.js index a4766b3..a3f5e2c 100644 --- a/src/lazybox.js +++ b/src/lazybox.js @@ -1,14 +1,14 @@ /** * LazyBox takes a function and 'boxes' it up. * - * @param func1 + * @param g * * LazyBox.map: takes a function parameter, returns a new LazyBox containing a function that composes the parameter with the boxed function. * LazyBox.fold: takes a function parameter, composes the parameter with the boxed function and returns the result. * LazyBox.inspect: returns a string-template showing the Boxed up value. */ -export const LazyBox = func1 => ({ - map: func2 => LazyBox(() => func2(func1())), - fold: (func2 = x => x) => func2(func1()) +export const LazyBox = g => ({ + map: f => LazyBox(() => f(g())), + fold: (f = x => x) => f(g()) });