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 / 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 / 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 / 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 / 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 / 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 / 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) {
//@flow
export type ExtractReturn<Fn> = $Call<<T>((...Iterable<any>) => T) => T, Fn>;
//example
const mapDispatchToProps = (dispatch: Dispatch) => ({
actions: {
setCompany: ({ companyId, domainName }) =>
dispatch(
//@flow
class Foo<Properties: Object> {
$key: $Keys<Properties> | 'c';
$value: $Values<Properties>;
}
@zerobias
zerobias / effector-terminal.js
Created June 22, 2018 08:33
Full-width terminal monitor for multiply parallel tests
//@flow
import {
createEvent,
createStore,
combine,
type Event,
type Store,
} from 'effector'
type graph_term('a) = {
nodes: list('a),
edges: list(('a, 'a)),
};
let example_graph = {
nodes: ['b', 'c', 'd', 'f', 'g', 'h', 'k'],
edges: [('h', 'g'), ('k', 'f'), ('f', 'b'), ('f', 'c'), ('c', 'b')],
};