View recurly.sh
This file contains 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 characters
# recurly does not document using cURL to access their API, they really want you to use their libraries. | |
# Sometimes i need to test something quick. I do not want to write a script importing your stupid library. | |
# So here's how you do it: | |
APIKEY=<get your API key from your recurly.com site> | |
curl -H "Accept: application/vnd.recurly.v2021-02-25+json" -u $APIKEY: https://v3.recurly.com/accounts |
View loop-recur.js
This file contains 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 characters
const Loop = (fn, ... init) => { | |
let r = fn (... init) | |
while (r instanceof Recur) r = fn (... r) | |
return r | |
} | |
const Recur = ( ...v) => Object .create ( | |
Recur .prototype, | |
{[Symbol .iterator]: {value: _ => v .values ()}} | |
) |
View glz.js
This file contains 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 characters
const NIL = Symbol('~~NIL~~'); | |
const isNil = x => typeof x === 'symbol' && x.toString() === NIL.toString(); | |
const pair = (a, b) => ({ | |
fst: function* () { yield a; }, | |
snd: function* () { yield b; }, | |
[Symbol.iterator]: function* () { yield a; (b[Symbol.iterator] ? yield* b : yield b); } | |
}); |
View store-comonad.js
This file contains 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 characters
/* | |
data Store s a = Store (s -> a) s | |
instance Functor (Store s) where | |
fmap f (Store g s) = Store (f . g) s | |
instance Extend (Store s) where | |
duplicate (Store f s) = Store (Store f) s | |
instance Comonad (Store s) where |
View s2.js
This file contains 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 characters
const S = { | |
fromArray: xs => sink => { | |
for (let i=0; i<xs.length; ++i) | |
if (sink(xs[i])) | |
return true | |
}, | |
map: fn => stream => sink => stream(x => sink(fn(x))), |
View curry.js
This file contains 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 characters
const meta = Symbol('@@ramda-meta'); | |
const initMeta = f => ({ func: f, arity: f.length, seenArgs: [] }); | |
const getMeta = f => f[meta] || initMeta(f); | |
const setMeta = (arg, f) => { | |
const fMeta = getMeta(f); | |
f[meta] = { | |
func: fMeta.func, |
View _stream.js
This file contains 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 characters
import Type from 'union-type'; | |
// `tail` function must be return a Stream type, but no way to enforce that without evaluating it :-( | |
const Stream = Type({ | |
Empty: [], | |
Cons: [() => true, Function] | |
}); | |
Stream.prototype.chain = function(f) { |
View Lazy.js
This file contains 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 characters
const fl = require('fantasy-land') | |
//- Lazy holds a vaue in a thunk, effectively delaying | |
//- evaluation until required. This is useful when we're | |
//- in a situation with either very large data set or | |
//- cyclical data. | |
//@ make stack-safe. | |
//> type Lazy a = Unit -> a | |
function Lazy(run) { |
View ct_notes.txt
This file contains 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 characters
CATEGORY THEORY FOR PROGRAMMERS | |
Category Theory 1.1: Motivation and Philosophy | |
https://www.youtube.com/watch?v=I8LbkfSSR58&index=1&list=PLbgaMIhjbmEnaH_LTkxLI7FMa2HsnawM_ | |
Composability, Abstraction, Reusability | |
Category Theory is a higher-level language. | |
Not a practical, executable language. |
View klotski.ml
This file contains 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 characters
(* | |
#1 | |
loop : ('a -> bool) -> ('a -> 'a) -> 'a -> 'a | |
such that loop p f x = x when p x = true and loop p f x = loop p f (f x) otherwise. | |
*) | |
let rec loop p f x = if p x then x else loop p f (f x);; | |
(* | |
#2 | |
exists : ('a -> bool) -> 'a list -> bool |
NewerOlder