Skip to content

Instantly share code, notes, and snippets.

@matthieubulte
matthieubulte / gist:27f0cb9f3d803e2632e0
Created June 11, 2014 06:41
cons/car/cdr in swift
func cdr<L, R>(p: () -> (L,R)) -> R {
let (l,r) = p()
return r
}
func car<L, R>(p: () -> (L,R)) -> L {
let (l,r) = p()
return l
}
@matthieubulte
matthieubulte / table.js
Last active August 29, 2015 14:07
purely functional table
// found this perl in "The Seasoned Schemer".
// just love how simple this implementation while coming
// with really great features.
function empty_table() {}
function extend(table, key, value) {
return function(k) {
if(k === key) {
return value;
class LazyList():
def __init__(self, iterable):
self._list = []
self._iterable = iter(iterable)
self._has_thrown = False
self._current_index = 0
def __iter__(self):
return self
import Data.Either
data Term = TTrue
| TFalse
| TIf Term Term Term
| TZero
| TSucc Term
| TPred Term
| TIsZero Term
type Reducer a r = r -> a -> r
type Transducer a b = forall r. Reducer a r -> Reducer b r
class Conjable f where
empty :: f a
conj :: Reducer a (f a)
class Foldable f where
fold :: Transducer a (f a)
interface Reducer<a, r> extends Function {
(z : r, x : a) : r;
}
interface Transducer<a, b> extends Function {
<r>(red : Reducer<a, r>) : Reducer<b, r>;
}
interface Unary<a, b> extends Function {
(x:a):b;
# flatten :: [[a]] -> [a]
def flatten(l):
return [x for lx in l for x in lx]
# first :: [a] -> a
def first(l):
return [l[0]] if l else []
# toString :: [Char] -> String
def toString(l):
var foo = {
"bar": {
"x": "test",
"y": 3
},
"list": [1, 2, 3, 4],
"obj_list": [
{
"x": "",
var MAX_ITEMS = 360;
var PAGE_SIZE = 10;
var PAGE_LOAD_THRESHOLD = 1 * 1000;
function AsyncRunner(options) {
var self = this;
var tasks = [];
var intervalIndex = -1;
module either {
export interface Either<L, R> {
isLeft():boolean;
isRight():boolean;
left():L;
right():R;
either<a>(
fl:(l:L)=>a,