This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const stack = (...values) => | |
| Object.create({ | |
| get: index => values[index], | |
| add: value => stack(...[value].concat(values)), | |
| remove: () => stack(...values.slice(1)), | |
| toString: () => `stack [${values.join(' ')}]`, | |
| toArray: () => values.slice(0), | |
| get length() { return values.length }, | |
| constructor: stack | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const memoize = fn => { | |
| const memo = {} | |
| return (...args) => { | |
| if (args in memo) return memo[args] | |
| return (memo[args] = fn.apply(null, args)) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const pipe = (...fns) => arg => | |
| fns.reduce((acc, fn) => fn(acc), arg) | |
| /* | |
| const a = x => `a(${x})` | |
| const b = x => `b(${x})` | |
| const c = x => `c(${x})` | |
| const piped = compose(a, b, c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const compose = (...fns) => | |
| fns.reduce((f, g) => (...args) => f(g(...args))) | |
| /* | |
| const a = x => `a(${x})` | |
| const b = x => `b(${x})` | |
| const c = x => `c(${x})` | |
| const composed = compose(a, b, c) | |
| composed('x') // a(b(c(x))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pubsub = {}; | |
| (function(q) { | |
| var topics = {}, subUid = -1; | |
| q.subscribe = function(topic, func) { | |
| if (!topics[topic]) { | |
| topics[topic] = []; | |
| } | |
| var token = (++subUid).toString(); | |
| topics[topic].push({ | |
| token: token, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const lower = str => str.toLowerCase() | |
| const upper = str => str.toUpperCase() | |
| const trim = str => str.trim() | |
| const exclaim = str => `${str}!!` | |
| const string = str => ({ | |
| get upper() { return string(upper(str)) }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const curry = (fn, ...args) => { | |
| if (args.length === fn.length) return fn(...args) | |
| return (...more) => curry(fn, ...args, ...more) | |
| } | |
| /* | |
| const add = (a, b, c) => a + b + c | |
| const curred = curry(add) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const propertyDescriptor = { enumerable: true, writable: false } | |
| export default class CustomError extends Error { | |
| constructor(message) { | |
| super(message) | |
| this.type = this.constructor.name | |
| Object.defineProperty(this, 'type', propertyDescriptor) | |
| Object.defineProperty(this, 'message', propertyDescriptor) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| // http://eslint.org/docs/rules/ | |
| "ecmaFeatures": { | |
| "binaryLiterals": false, // enable binary literals | |
| "blockBindings": false, // enable let and const (aka block bindings) | |
| "defaultParams": false, // enable default function parameters | |
| "forOf": false, // enable for-of loops | |
| "generators": false, // enable generators | |
| "objectLiteralComputedProperties": false, // enable computed object literal property names |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
| { | |
| "presets": ["es2015"], | |
| "plugins": [ | |
| "transform-decorators-legacy", | |
| "transform-async-to-generator" | |
| ] | |
| } |