Skip to content

Instantly share code, notes, and snippets.

View buzzdecafe's full-sized avatar
💭
quaquaquaqua

buzzdecafe

💭
quaquaquaqua
View GitHub Profile
@wvl
wvl / ramda.js
Last active August 29, 2015 14:03
Sample of ramda as built by bldr
(function(root,factory) { if (typeof define === "function" && define.amd) { define([], factory); } else { root.ramda = factory(); }})(this, function() {
// src/mkArgStr.js
var ramda = {};
var mkArgStr = ramda.mkArgStr = function(n) {
var arr = [], idx = -1;
while(++idx < n) {
arr[idx] = "arg" + idx;
}
return arr.join(", ");
@yuri
yuri / gist:62988af42efc4b920dd3
Last active August 29, 2015 14:09
Promise-Aware Compose
function pcompose() {
var step1;
var step2;
var tailArgs;
// TODO: Handle the case where only one argument is passed.
if (arguments.length === 2) {
step1 = arguments[1];
step2 = arguments[0];
return function(items) {
var value = step1(items);
require ('./globals')(global); // Mixed in Ramda to global here
var Task = require ('data.future'),
M = require ('control.monads'),
State = require ('fantasy-states'),
Reader = require ('fantasy-readers'),
Tuple2 = require ('fantasy-tuples').Tuple2,
Maybe = require ('data.maybe'),
ST = State.StateT (Task),
App = Reader.ReaderT (ST);
@kedashoe
kedashoe / gist:e0184a5b91e63084299b
Last active August 29, 2015 14:15
curry with placeholders curry2 and curry3
function curry2(fn) {
return function(a, b) {
switch (arguments.length) {
case 1:
return function(B) {
return fn(a, B);
};
default:
if (a === __) {
return function(A) {
@joneshf
joneshf / moore.js
Last active August 29, 2015 14:22
var R = require('ramda');
var Type = require('union-type-js');
// We need a base set of states: {`Q0`, `Q1`, `Q2`}.
var State = Type({Q0: [], Q1: [], Q2: []});
// We need an input alphabet: {`A`, `B`}.
var Sigma = Type({A: [], B: []});
// We need a transition function
// that takes a state and an element of the alphabet, and gives a new state.
@jethrolarson
jethrolarson / future_example.js
Last active August 29, 2015 14:23
Playing with Future
var R = require('ramda');
var Future = require('ramda-fantasy').Future;
//Wrap ajax in a future
//:: String -> Future String
var fetch = function(url) {
return new Future(function(rej, res){
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", res, false);
oReq.addEventListener("error", rej, false);
oReq.addEventListener("abort", rej, false);
@disnet
disnet / scheme.sjs
Created October 8, 2012 19:02
start of scheme in sweet.js (modified from http://pastebin.com/0nPBg8LY)
macro sexp {
case () => {
;
}
case ($p) => {
$p
}
case ($x $y) => {
$x($y);
}
function shift(arr, i) {
var cut = arr.length - i;
return arr.slice(cut).concat(arr.slice(0, cut));
}
var arr = [1,2,3,4,5];
shift(arr, 1); //[5, 1, 2, 3, 4]
shift(arr, 3); //[3, 4, 5, 1, 2]
var strategy = {};
strategy["slice"] = function () {
return Array.prototype.slice.call(arguments, 0);
};
strategy["cache slice"] = (function () {
var slice = Array.prototype.slice;
return function () {
return slice.call(arguments, 0);
};
}());