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
| function storify(target = {}) { | |
| const observers = {}, | |
| observables = {}; | |
| return new Proxy(target, { | |
| get: function(target, property, receiver) { | |
| if (property in observables === false) { | |
| observables[property] = Rx.Observable.create(observer => { | |
| observers[property] = observer; | |
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 wait = n => new Promise(res => setTimeout(res, n)); | |
| const log = console.log.bind(console); | |
| const dummy = payload => wait(1000).then(() => payload); | |
| const user = () => (log('user'), dummy({user: 'john'})); | |
| const tweets = () => (log('tweets'), dummy({tweets: ['asdasd', 'dsada']})); | |
| const github = () => (log('github'), dummy({repos: ['asdasd', 'dsada']})); | |
| // buildResult :: (user, tweets, github) -> {user, tweets, github} |
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
| {-# LANGUAGE GeneralizedNewtypeDeriving | |
| , ScopedTypeVariables | |
| #-} | |
| module Editor where | |
| import System.IO | |
| import Buffer | |
| import Control.Exception |
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
| function Reader(x) { | |
| this.x = x; | |
| } | |
| Reader.prototype.run = function(env) { | |
| return this.x(env); | |
| } | |
| Reader.of = function(x) { | |
| return new Reader(() => 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
| function State(fn) { | |
| this._fn = fn; | |
| } | |
| State.state = fn => new State(fn); | |
| State.of = val => State.state(state => [val, state]); | |
| State.get = State.state(state => [state, state]); |
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 reduce = reducer => z => as => as.reduce((z, a) => reducer(z)(a), z); | |
| // reducer :: (z -> a -> z) | |
| // transducer :: (z -> a -> z) -> (z -> b -> z) | |
| // contramapT :: (b -> a) -> (z -> a -> z) -> (z -> b -> z) | |
| const contramapT = fn => reducer => (z => b => reducer(z)(fn(b))); | |
| // filterT :: (a -> Bool) -> (z -> a -> z) -> (z -> a -> z) |
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
| // newtype Point = {x :: Number, y :: Number} | |
| // newtype EnhancedPoint = {x :: Number, y :: Number, visible :: Boolean, distance :: Number} | |
| /* Library functions */ | |
| // getCenter :: Point => Point => Point | |
| const getCenter = | |
| ({x: x1, y: y1}) => | |
| ({x: x2, y: y2}) => | |
| ({x: 0.5*(x1+x2), y: 0.5*(y1+y2)}) |
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 runConcurrently = concurrency => factories => { | |
| const queue = []; | |
| const lock = () => new Promise(resolve => { | |
| if (concurrency > 0) { | |
| concurrency-- | |
| resolve() | |
| } else { | |
| queue.push(resolve) | |
| } |
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 isObject = | |
| obj => | |
| obj instanceof Object; | |
| const isPromise = | |
| obj => | |
| typeof obj.then === 'function'; | |
| const mapDeepIf = | |
| (pr, fn, obj) => |
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
| class Estructura { | |
| constructor(datos) { | |
| this.datos = [-Infinity, -Infinity]; | |
| } | |
| insertar(dato) { | |
| this.datos[0] = this.datos[0] < dato ? dato : this.datos[0]; | |
| this.datos = sortPair(this.datos); | |
| return this; |
OlderNewer