-
-
Save ivn-cote/c42e3e52c7ddf61a0c9b to your computer and use it in GitHub Desktop.
Revisions
-
Avaq revised this gist
Feb 10, 2016 . 2 changed files with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ const I = x => x; const K = x => _ => x; const A = f => x => f(x); const T = x => f => f(x); const W = f => x => f(x)(x); const C = f => y => x => f(x)(y); const B = f => g => x => f(g(x)); const S = f => g => x => f(x)(g(x)); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ identity | **I** | id | identity | `a → a` constant | **K** | const | always | `a → b → a` apply | **A** | ($) | call | `(a → b) → a → b` thrush | **T** | (&) | | `a → (a → b) → b` duplication | **W** | | | `(a → a → b) → a → b` flip | **C** | flip | flip | `(a → b → c) → b → a → c` compose | **B** | (.) | compose | `(b → c) → (a → b) → a → c` substitution | **S** | | | `(a → b → c) → (a → b) → a → c` -
Avaq revised this gist
Feb 8, 2016 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,4 @@ flip | **C** | flip | flip | `(a → b → c) → b → a → c` compose | **B** | (.) | compose | `(b → c) → (a → b) → a → c` substitution | **S** | | | `(a → b → c) → (a → b) → a → c` psi | **P** | on | | `(b → b → c) → (a → b) → a → a → c` fix-point | **Y** | fix | | `(a → a) → a` -
Avaq revised this gist
Feb 1, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,6 @@ flip | **C** | flip | flip | `(a → b → c) → b → a → c` compose | **B** | (.) | compose | `(b → c) → (a → b) → a → c` substitution | **S** | | | `(a → b → c) → (a → b) → a → c` psi | **P** | on | | `(b → b → c) → (a → b) → a → a → c` fix | **Y** | fix | | `(a → a) → a` converge | | | converge | `(b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d` useWith | | | useWith | `(b -> d -> e) -> (a -> b) -> (c -> d) -> a -> c -> e` -
Avaq revised this gist
Feb 1, 2016 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ const ifElse = f => g => h => x => f(x) ? g(x) : h(x); const isZero = a => a < 1; const mult = a => b => a * b; const dec = a => a - 1; const factorial = Y(B(ifElse(isZero)(K(1)))(B(S(mult))(C(B)(dec)))); factorial(4); -
Avaq revised this gist
Jan 31, 2016 . 1 changed file with 0 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,3 @@ const {ifElse, dec} = R; const isZero = R.gt(1); const mult = a => b => a * b; -
Avaq revised this gist
Jan 31, 2016 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ const K = x => _ => x; const C = f => y => x => f(x)(y); const B = f => g => x => f(g(x)); const S = f => g => x => f(x)(g(x)); const Y = f => (g => g(g))(g => f(x => g(g)(x))); const {ifElse, dec} = R; const isZero = R.gt(1); const mult = a => b => a * b; const factorial = Y(B(ifElse(isZero, K(1)))(B(S(mult))(C(B)(dec)))); factorial(4); //> 24 -
Avaq revised this gist
Jan 31, 2016 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,12 +2,12 @@ Name | # | Haskell | Ramda | Signature ------------:|-------|---------|----------|---------- identity | **I** | id | identity | `a → a` constant | **K** | const | always | `a → b → a` apply | **A** | ($) | call | `(a → b) → a → b` thrush | **T** | (&) | | `a → (a → b) → b` flip | **C** | flip | flip | `(a → b → c) → b → a → c` compose | **B** | (.) | compose | `(b → c) → (a → b) → a → c` substitution | **S** | | | `(a → b → c) → (a → b) → a → c` psi | **P** | on | | `(b → b → c) → (a → b) → a → a → c` fix | **Y** | fix | | `(Any... -> a) f => (f -> f) -> f` converge | | | converge | `(b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d` useWith | | | useWith | `(b -> d -> e) -> (a -> b) -> (c -> d) -> a -> c -> e` -
Avaq revised this gist
Jan 31, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,3 +9,5 @@ compose | **B** | . | compose | `(b → c) → (a → b) → a → c substitution | **S** | | | `(a → b → c) → (a → b) → a → c` psi | **P** | on | | `(b → b → c) → (a → b) → a → a → c` fix | **Y** | | | `(Any... -> a) f => (f -> f) -> f` converge | | | converge | `(b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d` useWith | | | useWith | `(b -> d -> e) -> (a -> b) -> (c -> d) -> a -> c -> e` -
Avaq revised this gist
Jan 31, 2016 . No changes.There are no files selected for viewing
-
Avaq revised this gist
Jan 31, 2016 . 4 changed files with 0 additions and 75 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,30 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,34 +0,0 @@ File renamed without changes. -
Avaq revised this gist
Jan 31, 2016 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ Name | # | Haskell | Ramda | Signature ------------:|-------|---------|----------|---------- identity | **I** | id | identity | `a → a` constant | **K** | const | always | `a → b → a` apply | **A** | $ | call | `(a → b) → a → b` thrush | **T** | | | `a → (a → b) → b` flip | **C** | flip | flip | `(a → b → c) → b → a → c` compose | **B** | . | compose | `(b → c) → (a → b) → a → c` substitution | **S** | | | `(a → b → c) → (a → b) → a → c` psi | **P** | on | | `(b → b → c) → (a → b) → a → a → c` fix | **Y** | | | `(Any... -> a) f => (f -> f) -> f` -
Avaq revised this gist
Jan 30, 2016 . 3 changed files with 20 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ const I = x => x; const K = x => _ => x; const A = f => x => f(x); const T = x => f => f(x); const C = f => y => x => f(x)(y); const B = f => g => x => f(g(x)); const S = f => g => x => f(x)(g(x)); const P = f => g => x => y => f(g(x))(g(y)); const Y = f => (g => g(g))(g => f(x => g(g)(x))); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ const head = xs => xs[0]; const tail = xs => xs.slice(1); const add = a => b => a + b; const dot = Y(f => n => n < 1 ? '' : '.' + f(n - 1)); const factorial = Y(f => n => n < 1 ? 1 : n * f(n - 1)); const reduce = f => Y(g => y => xs => xs.length < 1 ? y : g(f(y)(head(xs)))(tail(xs))); dot(3) //> "..." factorial(4) //> 24 reduce(add)(0)([1, 2, 3]) //> 6 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +0,0 @@ -
Avaq revised this gist
Jan 30, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ const Y = f => (g => g(g))(g => f(x => g(g)(x))); const factorial = Y(f => n => n < 1 ? 1 : n * f(n - 1)); factorial(4) -
Avaq revised this gist
Jan 29, 2016 . 1 changed file with 34 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ console.clear(); const then = Date.now(); const log = x => console.log(`${Date.now() - then} - ${x}`); const err = x => console.log(`${Date.now() - then} - ERROR: ${x}`); const {K, I, pipe} = S; const {curry, reduce, ap, once, compose, chain, map} = R; const ftap = f => a => f(a).map(K(a)); //A mock database const connect = curry(config => (log('Connecting...'), Future.of({name: 'Connection', config}))) const close = curry(connection => Future((rej, res) => (log(`Closed ${connection.name}`), res(null)))) const query = curry((x, connection) => Future((rej, res) => setTimeout(() => (log(`QUERY[${x}]`), res(eval(x))), 300) )); const RFuture = Reader.T(Future); const app = RFuture(chain(query('1 + 1'))); const closeConnection = () => RFuture.ask.chain(pipe([ chain(close), RFuture.lift ])); const querySquare = n => RFuture.ask.chain(pipe([ query(`${n} * ${n}`), RFuture.lift ])) app .chain(querySquare) .chain(ftap(closeConnection)) .run(connect({foo: 'bar'})) .fork(err, log) -
Avaq revised this gist
Jan 18, 2016 . 1 changed file with 13 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,6 @@ //Combinators const I = x => x; //List manipulation const head = xs => xs[0]; const tail = xs => xs.slice(1); @@ -13,11 +10,21 @@ const append = x => xs => [...xs, x]; const foldl = f => y => xs => xs.length > 0 ? foldl(f)(f(y)(head(xs)))(tail(xs)) : y; const foldr = f => y => xs => xs.length > 0 ? f(foldr(f)(y)(tail(xs)))(head(xs)) : y; const map = f => foldl(y => x => append(f(x))(y))([]); const filter = f => foldl(y => x => f(x) ? append(x)(y) : y)([]); //Function composition const compose = f => g => x => f(g(x)); const pipe = foldr(compose)(I); //Math const add = a => b => a + b; const mult = a => b => a * b; const gt = a => b => b > a; //Program pipe([ map(add(1)), map(mult(2)), filter(gt(10)) ]) ([1, 2, 3, 4, 5, 6, 7, 8]); -
Avaq revised this gist
Jan 18, 2016 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ const {map, join, addIndex, chain, isEmpty, insert, remove} = R; const cat = map(join('')); const ichain = addIndex(chain); //permutations :: [a] -> [[a]] const permutations = xs => isEmpty(xs) ? [[]] : ichain( (x, i) => map(R.insert(0, x), permutations(remove(i, 1, xs))), xs ); cat(permutations(['A', 'B', 'C'])); -
Avaq created this gist
Jan 17, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ //Combinators const I = x => x; //Function composition const compose = f => g => x => f(g(x)); //List manipulation const head = xs => xs[0]; const tail = xs => xs.slice(1); const append = x => xs => [...xs, x]; //Iteration const foldl = f => y => xs => xs.length > 0 ? foldl(f)(f(y)(head(xs)))(tail(xs)) : y; const foldr = f => y => xs => xs.length > 0 ? f(foldr(f)(y)(tail(xs)))(head(xs)) : y; const map = f => foldl(y => x => append(f(x))(y))([]); //Lib const add = a => b => a + b; const mult = a => b => a * b; const pipe = foldr(compose)(I); //Program map(pipe([add(1), mult(2)]))([1, 2, 3]);