Skip to content

Instantly share code, notes, and snippets.

View micha149's full-sized avatar

Michael van Engelshoven micha149

  • Brainbits GmbH
  • Sankt Augustin, Germany
View GitHub Profile
@micha149
micha149 / asyncPipe.ts
Last active March 19, 2018 12:49
Functional, static typed, promised approach for handling async stuff
type Arity1<A, B> = (a: A) => Promise<B>;
function asyncPipe<A, B>(f: Arity1<A, B>): Arity1<A, B>;
function asyncPipe<A, B, C> (g: Arity1<A, B>, f: Arity1<B, C>): Arity1<A, C>;
function asyncPipe<A, B, C, D> (h: Arity1<A, B>, g: Arity1<B, C>, f: Arity1<C, D>): Arity1<A, D>;
function asyncPipe<A, B, C, D, E> (i: Arity1<A, B>, h: Arity1<B, C>, g: Arity1<C, D>, f: Arity1<D, E>): Arity1<A, E>;
function asyncPipe<A, B, C, D, E, F> (j: Arity1<A, B>, i: Arity1<B, C>, h: Arity1<C, D>, g: Arity1<D, E>, f: Arity1<E, F>): Arity1<A, F>;
export default function asyncPipe (...fns) {
return x => fns.reduce(async (y, f) => f(await y), x);
@micha149
micha149 / Counter.jsx
Last active May 23, 2018 15:15
Just testing around with clean functional react components and the question how to get state in a stateless function. The answer is composition.
import React from 'react';
import PropTypes from 'prop-types';
const propTypes = {
count: PropTypes.number.isRequired,
onIncrement: PropTypes.func.isRequired,
onDecrement: PropTypes.func.isRequired,
};
const Counter = ({ count, onIncrement, onDecrement }) => (
@micha149
micha149 / index.js
Created September 4, 2019 10:57
Buffered RXJS
const { rxObserver } = require('api/v0.3');
const { interval, from, timer, of } = require('rxjs');
const { take, bufferCount, concatMap, delay, first, mergeMap, map, throttleTime, ignoreElements, startWith } = require('rxjs/operators');
const spaceTime = time => concatMap(value =>
of(value).pipe(
delay(time)
)
);