Skip to content

Commit

Permalink
feat: functional programming
Browse files Browse the repository at this point in the history
  • Loading branch information
trmaphi committed Jan 24, 2020
1 parent 4285981 commit 73e61a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions functional-programming.js/compose-function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const f = n => n * 2;
const g = n => n + 1;
const h = x => f(g(x));

console.log(h(20))

// Algebra function composition
/**
* g: a -> b
* f: b -> c
* h: a -> c
* f(g(x)) = h(x)
*/

const compose2 = (f, g) => x => f(g(x));

console.log(compose2(n => n * 2, n => n + 1)(20))

const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x);

console.log(compose2(n => n * 2, n => n + 1)(20))
3 changes: 3 additions & 0 deletions functional-programming.js/curry-function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const add = a => b => a + b;

console.log(add(5)(5));

0 comments on commit 73e61a9

Please sign in to comment.