Skip to content

Instantly share code, notes, and snippets.

View abiodun0's full-sized avatar

Abiodun abiodun0

View GitHub Profile
@abiodun0
abiodun0 / lambda.js
Last active March 14, 2019 13:16
Lambda & javascript
// # Lambda as JS, or A Flock of Functions
// ### Combinators, Lambda Calculus, and Church Encodings in JavaScript
// #### Notes for [a talk by Gabriel Lebec
// (click for videos and slides)](https://www.youtube.com/watch?v=3VQ382QG-y4&list=PLpkHU923F2XFWv-XfVuvWuxq41h21nOPK&index=1)
const chalk = require('chalk')
const green = chalk.green.bind(chalk)
const red = chalk.red.bind(chalk)
@abiodun0
abiodun0 / typeTheorywithEval.hs
Created August 15, 2018 05:51
Eval and types
import Data.Either
data Term = TTrue
| TFalse
| TIf Term Term Term
| TZero
| TSucc Term
| TPred Term
| TIsZero Term
@abiodun0
abiodun0 / cons.js
Last active January 27, 2023 23:22
For next blog post con cdr car
const cons = (x, y) => (m) => m(x, y)
const car = (z) => z((p, q) => p)
const cdr = (z) => z((p, q) => q)
const someLinkedList = cons(1, cons(2, cons(3 , null)))
// iterating
@abiodun0
abiodun0 / writerMonadFizzBuzz.js
Created July 16, 2018 06:02
gist for first blog post
const makeMonad = (prevData, prevLog) => fn => {
const newData = fn(prevData).data;
const newLog = prevLog + fn(prevData).log;
return { data: newData,
log: newLog,
bind: makeMonad(newData, newLog)
};
};
const pure = x => ({
@abiodun0
abiodun0 / runkitMonad.js
Created July 16, 2018 04:45
Fluture with runkit monad
require("@babel/polyfill")
const { implement, Functor } = require("@masaeedu/fp")
const Fluture= require("fluture")
// We can just get map from of and chain for free everywhere
const deriveFunctor = implement(Functor)
// Identity monad
const id = x => x;
@abiodun0
abiodun0 / itero-recursive.js
Created July 15, 2018 06:39
itero recursive algorithm for signly linked list, fibonnaci, depth first and bread first search
function fibs(n) {
let [last, curr] = [0, 1];
for (let i = 0; i < n; i++) {
[last, curr] = [curr, last + curr];
}
return last; // think: why isn't this `curr`?
}
// fibs(3)
// 0 1 3 4 7
// 0 1 1 2 3 5
@abiodun0
abiodun0 / MaybT.js
Last active July 15, 2018 06:19
Maybe T example
const Fluture= require("fluture")
// We can just get map from of and chain for free everywhere
const deriveFunctor = M => ({ ...M, map: f => M.chain(x => M.of(f(x))) })
// Identity monad
const id = x => x;
const Identity = deriveFunctor({ of: id, chain: id });
const Maybe = (() => {
@abiodun0
abiodun0 / type.hs
Last active April 10, 2018 11:33
Proof of type
import Data.Either
data Term = TTrue
| TFalse
| TIf Term Term Term
| TZero
| TSucc Term
| TPred Term
| TIsZero Term
@abiodun0
abiodun0 / modulehot.js
Created March 27, 2018 10:41
Some simple hot reloading
if (module.hot) {
module.hot.accept('./components/root/RootComponent.js', () => {
const FdyRootComponent = require('./components/root/RootComponent.js').FdyRootComponent
ReactDOM.unmountComponentAtNode(node)
ReactDOM.render(
<Provider store={store}>
<RouterProvider router={router.routerInstance}>
<FdyRootComponent />
</RouterProvider>
@abiodun0
abiodun0 / Read.js
Last active March 14, 2018 09:42
Reader Monad
function Reader(x) {
this.x = x;
}
Reader.prototype.run = function(env) {
return this.x(env);
}
Reader.of = function(x) {
return new Reader(() => x);