Skip to content

Commit

Permalink
Extending README
Browse files Browse the repository at this point in the history
  • Loading branch information
karudedios committed Oct 20, 2015
1 parent 17040ac commit 1f2ef74
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
77 changes: 76 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,82 @@ let oddAction = (n) => n * 2;
return (v % 2 === 0 ? Identity : oddAction)(v);
```

This isn't the best example, but there's probaby no -good- example, since Identity simply returns whatever you throw at him.
This isn't the best example, but there's probaby no *best* example, since Identity simply returns whatever you throw at him.

### Pipe
Takes care of passing a value through multiple functions in a left-associative manner.

```javascript
/* Regular Approach */

let addTwo = (v) => v + 2;
let timesTen = (v) => v * 10;
let minusThree = (v) => v - 3;

let r1 = addTwo(5);
let r2 = timesTen(r1);
let r3 = MinusThree(r2);

return r3;

/* Pipe Approach */

import { pipe } from "functional-programming-utilities";

let addTwo = (v) => v + 2;
let timesTen = (v) => v * 10;
let minusThree = (v) => v - 3;

return pipe(5, addTwo, timesTen, minusThree);
```

### Compose
Joins n functions in a left-associative manner to be called one after another when invoked.

```javascript
/* Regular Approach */

let addTwo = (v) => v + 2;
let timesTen = (v) => v * 10;
let minusThree = (v) => v - 3;

return minusThree(timesTen(addTwo(5)));

/* Compose Approach */

import { compose } from "functional-programming-utilities";

let addTwo = (v) => v + 2;
let timesTen = (v) => v * 10;
let minusThree = (v) => v - 3;

return compose(addTwo, timesTen, minusThree)(5);
```

### Curry
Takes a function that receives n parameters and yields a function that will wait until n parameters are provided before invoking the original function.

```javascript
/* Regular Approach */

let divide = (a, b) => a / b;
// divide(10) => undefined; divide(10, 2) => 5

let divideBy = (b) => (a) => a / b;
// divideBy(10) => Function; divideBy(2)(10) => 5

let halve = divideBy(2);
return halve(10);

/* Curry Approach */

let divide = curry((b, a) => a / b);
// divide(10) => Function; divide(2, 10) => 5; divide(2)(10) => 5

let halve = divide(2);

return halve(10);
```

### Given
Replacement for `switch/case` and `if/else if/else`
Expand Down
2 changes: 1 addition & 1 deletion lib/Curry.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default (() => {
Object.defineProperty(curried, 'arity', { value: fn.arity, writable: true });

return curried;
}
};

return { curry };
})();

0 comments on commit 1f2ef74

Please sign in to comment.