Skip to content

Instantly share code, notes, and snippets.

@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,
@matthieubulte
matthieubulte / gist:fdc76857ff79e5fdb0e7
Created February 26, 2015 12:29
AngularJS directives partial application
var app = angular.module('test', []);
function capitalize(word) {
return word.charAt(0).toUpperCase() + word.slice(1);
}
function id(a) {
return a;
}