Skip to content

Instantly share code, notes, and snippets.

View briancavalier's full-sized avatar

Brian Cavalier briancavalier

  • Pittsburgh
View GitHub Profile
@briancavalier
briancavalier / esnextbin.md
Created May 6, 2016 01:49
esnextbin sketch
@briancavalier
briancavalier / esnextbin.md
Last active May 5, 2016 02:50
esnextbin sketch
import most from 'most'
const add1 = x => x + 1
const even = x => x % 2 === 0
const sum = (x, y) => x + y
const newArray = n => {
const a = new Array(n)
for (let i = 0; i < n; ++i) {
a[i] = i
|====\____/====/============\=/===========|================|
|              |    ____    |/      ____//|                |
|              |   |    |   |      //_____|_____|    |_____|                    
|    |\==/|    |   |    |   |______       \\    |    |
|    | \/ |    |    \==/    |    \\/      //    |    |
|____|    |____|____________|___________//      |____|
@briancavalier
briancavalier / esnextbin.md
Last active April 12, 2016 11:11
esnextbin sketch
@briancavalier
briancavalier / proxy.js
Created March 30, 2016 13:11
Stream proxy that can be told to imitate another stream
import { Stream, observe, periodic } from '../most'
import defaultScheduler from '../lib/scheduler/defaultScheduler'
const proxy = () => {
const source = new Source()
return {
imitate: stream => imitateStream(stream, source),
stream: new Stream(source)
}
}
@briancavalier
briancavalier / esnextbin.md
Created March 8, 2016 02:01
esnextbin sketch
@briancavalier
briancavalier / most-sample-promises.md
Last active November 19, 2019 16:47
Description of most.js sample+promises issue

This is an explanation of the extremely subtle problem in this most.js issue. This solution described isn't necessarily the best, or most rigorous solution. We're investigating other potential solutions, but wanted to record this information in case it's interesting to someone.

Background

One of the fastest ways to schedule a task in ES6 is to use a promise. They tend to use the fastest micro-tick scheduling option the platform provides. So, when a task is scheduled with scheduler.asap it doesn’t use setTimeout 0, it uses a promise to schedule itself, because that’s basically as close to zero-time as you can get in a platform independent way

given this:

@briancavalier
briancavalier / esnextbin.md
Created March 4, 2016 17:17
esnextbin sketch
@briancavalier
briancavalier / race.md
Last active March 4, 2016 17:12
Recipe for racing two streams

Needs a description, and a meaningful example ...

import { merge } from 'most'

// race :: Stream a -> Stream a -> Stream a
// return a stream that imitates the input stream with
// the earliest first event
const race = (s1, s2) =>
 merge(mapToSelf(s1), mapToSelf(s2)).take(1).join()