Skip to content

Commit

Permalink
LazyBox docs
Browse files Browse the repository at this point in the history
  • Loading branch information
phixid committed Dec 10, 2017
1 parent e0fd965 commit b3e7751
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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())
});
```
8 changes: 4 additions & 4 deletions dist/cjs/subterfuge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
});

/**
Expand Down
8 changes: 4 additions & 4 deletions dist/es/subterfuge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
});

/**
Expand Down
8 changes: 4 additions & 4 deletions src/lazybox.js
Original file line number Diff line number Diff line change
@@ -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())
});

0 comments on commit b3e7751

Please sign in to comment.