Skip to content

Instantly share code, notes, and snippets.

View zerobias's full-sized avatar
💭
Set your status

Dmitry zerobias

💭
Set your status
View GitHub Profile
@zerobias
zerobias / topological-sort.js
Created May 18, 2018 05:05
Topological sort
function toposortDFS(edges, begin){
const inEdges = new Map()
const outEdges = new Map()
const vertices = new Set()
const result = new Set()
for (const [edge, dep] of edges) {
vertices.add(edge)
vertices.add(dep)
}
for (const vertex of vertices) {
@zerobias
zerobias / multiMap.js
Last active May 9, 2018 03:04
Multi Map / Multi Set
//@flow
export class MultiMap<A, B, C> {
/*::+*/ inner: Map<A, Map<B, C>> = new Map()
get(a: A, b: B): C | void {
const subset = this.inner.get(a)
if (subset === undefined) return
return subset.get(b)
}
set(a: A, b: B, c: C) {
@zerobias
zerobias / rw.js
Last active April 19, 2018 12:51
RW
//@flow
type R<+_> = (_: any) => _
type W<-_> = (_: _) => any
type RR<-a, -b, +c> = (a: R<a>, b: R<b>) => R<c>
type WW<+a, +b, -c> = (a: W<a>, b: W<b>) => W<c>
type R$map<-a, +b> = (a: R<a>) => R<b>
type W$map<+a, -b> = (a: W<a>) => W<b>
@zerobias
zerobias / unit.js
Created March 29, 2018 01:05
Unit type
//@flow
const Unit = _ => Unit
Object.assign(Unit, {
pred: _ => false,
scope: Unit,
block: Unit,
body: Unit,
read: Unit,
@zerobias
zerobias / index.js
Created March 27, 2018 14:19
Applicative wrapper
//@flow
import {interpret} from './wrap'
const foo = () => interpret(new Set([0, 1, 2]))
.map(x => x + 1)
.ap( interpret(new Set([x => x * 10])) )
@zerobias
zerobias / flo.sh
Last active March 19, 2018 08:24
Flow runner
#!/usr/bin/env bash
node_modules/.bin/flow status --show-all-errors --message-width=80 --no-auto-start --timeout=15 --strip-root --color=always
@zerobias
zerobias / .eslintrc.yml
Created February 28, 2018 20:26
.eslintrc
parser: babel-eslint
parserOptions:
ecmaVersion: 8
ecmaFeatures:
experimentalObjectRestSpread: true
extends:
- 'plugin:flowtype/recommended'
plugins:
- babel
- flowtype
@zerobias
zerobias / effects.js
Last active February 11, 2018 21:20
Effector example
//@flow
import {
ping,
submitLogin,
requestAuth,
showNotification,
} from './events'
import type {State} from './state'
//@flow
import type {Stream} from 'most'
function intoAsync<T>(str: Stream<T>): $AsyncIterable<T, void, any> {
let isEnd = false
let ask: Array<Dispose<T>> = []
let tell: Array<T> = []
const end = str.observe(t => {
if (ask.length > 0) {
@zerobias
zerobias / most.js
Created January 24, 2018 06:54
most flow typings
//@flow
export type SeedValue<S, V> = {
seed: S,
value: V,
}
export type TimeValue<V> = {
/*::+*/time: number,
/*::+*/value: V
}