Skip to content

Instantly share code, notes, and snippets.

View renaudtertrais's full-sized avatar

Renaud TERTRAIS renaudtertrais

View GitHub Profile
@renaudtertrais
renaudtertrais / zip.js
Created July 5, 2016 13:59
A simple ES6 zip function
const zip = (arr, ...arrs) => {
return arr.map((val, i) => arrs.reduce((a, arr) => [...a, arr[i]], [val]));
}
// example
const a = [1, 2, 3];
const b = [4, 5, 6];
const c = [7, 8, 9];
@renaudtertrais
renaudtertrais / bind.js
Last active July 4, 2016 16:08
A simple ES6 bind function to implement Railway oriented programming. https://vimeo.com/113707214
const compose = (...fns) => (...args) => {
return fns.slice(0, -1).reduceRight((res, fn) => fn(res),
fns[fns.length -1].apply(null,args)
);
};
const bind = (f) => (...args) => {
if(args[0] instanceof Error) return args[0];
try{
return f.apply(null, args);
@renaudtertrais
renaudtertrais / partial.js
Last active February 10, 2017 12:45
Simple ES6 partial function
const partial = (fn, ...args) => partialApply(fn, args);
const partialApply = (fn, args) => fn.bind(null, ...args);
// example
const add = (a, b) => a + b;
const sum = (...args) => args.reduce(add, 0);
const add10 = partial(sum, 4, 6);
const add40 = partialApply(sum, [5, 15, 20]);
@renaudtertrais
renaudtertrais / compose.js
Last active December 16, 2020 06:34
Simple ES6 compose & pipe function
const compose = (...fns) => (...args) => {
return fns.slice(0, -1).reduceRight((res, fn) => fn(res),
fns[fns.length -1].apply(null,args)
);
};
const pipe = (f1, ...fns) => (...args) => {
return fns.reduce((res, fn) => fn(res), f1.apply(null,args));
};
@renaudtertrais
renaudtertrais / curry.js
Last active September 1, 2017 09:43
A simple ES6 curry function
const curry = (fn, ...args) => fn.length === 0
? fn
: fn.length > args.length
? (...args2) => curry(...[fn,...args,...args2])
: fn(...args);
// example
const add = curry((a,b,c,d) => a + b + c + d);
const add1 = add(1);
const add3 = add1(2);
@renaudtertrais
renaudtertrais / _positions.scss
Last active February 5, 2022 17:34
Sass position mixins
// ----
// Sass (v3.4.14)
// Compass (v1.0.3)
// ----
@mixin pos-absolute($positions...){
position: absolute;
@include position($positions...);
}
DataSystem = () ->
this.data = {}
this
proto = DataSystem.prototype
proto.set = ( keys , value , obj ) ->
obj = obj || this.data
if typeof keys is 'string'
keys = keys.split('.')
@renaudtertrais
renaudtertrais / Collection.js
Created December 28, 2014 21:48
Automatize querySelectorAll manipulation.
var t = console.log;
var select = function( selector ){
return new Collection( document.querySelectorAll( selector ) );
};
var Collection = function( collection ){
collection = collection || [];
this.collection = Array.prototype.slice.call(collection);