Skip to content

Instantly share code, notes, and snippets.

View marcoslhc's full-sized avatar
🏳️‍🌈
He's like the rainbow

Marcos Hernández marcoslhc

🏳️‍🌈
He's like the rainbow
View GitHub Profile
@marcoslhc
marcoslhc / keybase.md
Created April 29, 2017 13:21
keybase.md

Keybase proof

I hereby claim:

  • I am marcoslhc on github.
  • I am marcoslhc (https://keybase.io/marcoslhc) on keybase.
  • I have a public key ASDLabcN5vXDb0S9oe_pdXN5_qQUj7PTUp3IEy0mhX6zIAo

To claim this, I am signing this object:

const compose =
(...funcs) => arg => funcs.reduceRight((composed, f) => f(composed), arg);
const filterReduce =
predicate => reducer => (accum, value) => (predicate(value)) ? reducer(accum, value) : accum;
const mapReduce =
morphism => reducer => (accum, value) => reducer(accum, morphism(value));
const transduce =
range = (start, end, step = 1) => {
return {
*[Symbol.iterator]() {
let by = start >= end && step > 0 ? step*(-1) : step;
let current = start;
while ((start < end && current < end) || (start > end && current > end)) {
yield current;
current = current + by;
}
return end;
@marcoslhc
marcoslhc / transducer_composed.js
Last active April 9, 2017 01:38
Transducer composed
// Stripped straight from the good Dan Abramov
// https://gist.github.com/gaearon/ffd88b0e4f00b22c3159
function compose(...functions) {
return function (arg) {
return functions.reduceRight(function (composed, f) {
return f(composed);
}, arg);
};
};
@marcoslhc
marcoslhc / filter_map_reduce.js
Last active April 8, 2017 04:15
filter -> map -> reduce
function filterReduce(predicate) {
return function (accum, value) {
if (predicate(value)) {
return accum.concat(value);
} else {
return accum;
}
};
};
@marcoslhc
marcoslhc / fstddev.js
Created April 7, 2017 03:22
Functional Standard Deviation
// Utilities
const compose =
(...fns) => (arg) => fns.reduceRight((composed, func) => func(composed), arg);
const map =
fn => list => list.map(fn);
const filter =
predicate => list => list.filter(predicate);
@marcoslhc
marcoslhc / array_reduce_matrix.js
Last active April 6, 2017 01:27
Array Reduce Matrix Product
var matrix1 = [
[1, 1, 4, 5],
[0, 3, 3, 2],
[3, 1, 1, 0]
]
var coeficients = [0.3, 0.5, 0.2];
function weirdComputation(matrix) {
var m = matrix;
@marcoslhc
marcoslhc / array_reduce_concat.js
Created April 6, 2017 00:32
array reduce concat
var arr = ['The', 'simple', 'things', 'of', 'life']
arr.reduce(function (finalString, str) {
return finalString.concat(' ').concat(str)
}, '');
// " The simple things of life"
// reduce folds the value from left to righ, we could also reduce from right to left:
var arr = 'stressed'.split('');
@marcoslhc
marcoslhc / array_reduce_sum.js
Last active April 6, 2017 00:31
reduce sum
let arr = [1,2,3,4,5,6,7,8,9,10];
// Array.prototype.reduce takes a function (reducer) and an initial value of type B
// and returns an value of type B
let num = arr.reduce(function (accum, value) {
// The reducer function takes a value of
// type B and another value of the same type as the array (A)
// returns a value of type B;
return accum + value;
ClassList.prototype.concat = function (otherList) {
return ClassList.of(this.getClasses().concat(otherList.getClasses()));
}
// We check if it's a value we can work on. There are some other
// checks we need to make, but this is not the place to do it
ClassList.prototype.addClass = function (classes) {
const classesToAdd = Array.isArray(classes) ? classes
: [classes];
return ClassList.of(this.getClasses()).concat(ClassList.of(classesToAdd));