Skip to content

Instantly share code, notes, and snippets.

@alesanabv
Created November 24, 2016 01:02
Show Gist options
  • Save alesanabv/a63f1a0cfae3fc482333723cd8598b3b to your computer and use it in GitHub Desktop.
Save alesanabv/a63f1a0cfae3fc482333723cd8598b3b to your computer and use it in GitHub Desktop.
my own functional lib, only for learning
'use strict';
export const each = fn => arr => Array.prototype.forEach.call(arr, fn);
export const map = fn => arr => Array.prototype.map.call(arr, fn);
export const reduce = (fn, initial = {}) => arr => Array.prototype.reduce.call(arr, fn, initial);
export const on = (event, fn) => el => el.addEventListener(event, fn);
export const onAll = (event, fn) => each(on(event, fn));
export const flatten = arr => reduce((a, b) => a.concat(b), [])(arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment