Skip to content

Instantly share code, notes, and snippets.

View dwickstrom's full-sized avatar
🐎

David Wickström dwickstrom

🐎
View GitHub Profile
from itertools import chain, imap
def curry(fn):
def curried(*args, **kwargs):
if len(args) + len(kwargs) >= fn.__code__.co_argcount:
return fn(*args, **kwargs)
return (lambda *args2, **kwargs2:
curried(*(args + args2), **dict(kwargs, **kwargs2)))
return curried
@dwickstrom
dwickstrom / p.js
Created August 24, 2017 10:45
Fantasy Land Promise
Promise.of = Promise.resolve
Promise.prototype.chain = Promise.prototype.then
Promise.prototype.map = Promise.prototype.then
Promise.prototype.ap = function (other) {
this.chain(f => other.map(x => f(x)))
}
// unit :: Applicative a => a -> b -> a b
const of = t => x => t.of(x)
of (Right) (1)
function * xrange (step, start, stop) {
let i = start
while (i < stop) {
yield i
i = i + step
}
}
@dwickstrom
dwickstrom / zip.js
Last active July 6, 2017 09:34
Zip impl
//+ zip :: [a] -> [b] -> [(a, b)]
const zip = ([x, ...xs]) => ([y, ...ys]) =>
[[x, y], ...zip (xs) (ys)]
const zip = xs => ys =>
xs.reduce((acc, curr, idx) =>
[[curr, ys[idx]], ...acc], [])
@dwickstrom
dwickstrom / heads-tails.js
Created July 5, 2017 16:21
destructure head/tail from list
// take :: Int -> [a] -> [a]
const take = n => ([x, ...xs]) =>
!x ?
[] :
n === 0 ?
[] :
[x, ...take (n-1) (xs)]
@dwickstrom
dwickstrom / pattern-matching.js
Last active January 1, 2018 12:24
JS pattern matching
// fooIsBar :: Int -> String
const fooIsBar = x =>
x == 1 ? 'one'
: x == 2 ? 'two'
: x == 3 ? 'three'
: x == 4 ? 'four'
: /* or */ 'too much'

Keybase proof

I hereby claim:

  • I am dwickstrom on github.
  • I am dwickstrom (https://keybase.io/dwickstrom) on keybase.
  • I have a public key ASC9XLlpE9HjjPKrx6xLsiUrus-PsONoWrT4wmmJass3qwo

To claim this, I am signing this object:

@dwickstrom
dwickstrom / foo.sh
Created May 2, 2017 09:21
Remove dangling images
docker rmi $(docker images -qa -f 'dangling=true')
@dwickstrom
dwickstrom / $.js
Last active May 19, 2018 18:43
Little DOM query thing
export const $ = (selector, scope=document) =>
Array
.of(scope.querySelector(selector))
.filter(x => x)
export const $$ = (selector, scope=document) =>
Array.from(scope.querySelectorAll(selector))