Created
October 10, 2017 04:17
-
-
Save mattpodwysocki/3cad90db7c86e53354c16317e7c2c52e to your computer and use it in GitHub Desktop.
This file contains 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
import { OperatorAsyncFunction } from '../interfaces'; | |
import { AsyncIterableX } from '../asynciterable'; | |
/* tslint:disable:max-line-length */ | |
export function pipe<T>(source: AsyncIterable<T>): AsyncIterableX<T>; | |
export function pipe<T, A>(source: AsyncIterable<T>, op1: OperatorAsyncFunction<T, A>): AsyncIterableX<A>; | |
export function pipe<T, A, B>(source: AsyncIterable<T>, op1: OperatorAsyncFunction<T, A>, op2: OperatorAsyncFunction<A, B>): AsyncIterableX<B>; | |
export function pipe<T, A, B, C>(source: AsyncIterable<T>, op1: OperatorAsyncFunction<T, A>, op2: OperatorAsyncFunction<A, B>, op3: OperatorAsyncFunction<B, C>): AsyncIterableX<C>; | |
export function pipe<T, A, B, C, D>(source: AsyncIterable<T>, op1: OperatorAsyncFunction<T, A>, op2: OperatorAsyncFunction<A, B>, op3: OperatorAsyncFunction<B, C>, op4: OperatorAsyncFunction<C, D>): AsyncIterableX<D>; | |
export function pipe<T, A, B, C, D, E>(source: AsyncIterable<T>, op1: OperatorAsyncFunction<T, A>, op2: OperatorAsyncFunction<A, B>, op3: OperatorAsyncFunction<B, C>, op4: OperatorAsyncFunction<C, D>, op5: OperatorAsyncFunction<D, E>): AsyncIterableX<E>; | |
export function pipe<T, A, B, C, D, E, F>(source: AsyncIterable<T>, op1: OperatorAsyncFunction<T, A>, op2: OperatorAsyncFunction<A, B>, op3: OperatorAsyncFunction<B, C>, op4: OperatorAsyncFunction<C, D>, op5: OperatorAsyncFunction<D, E>, op6: OperatorAsyncFunction<E, F>): AsyncIterableX<F>; | |
export function pipe<T, A, B, C, D, E, F, G>(source: AsyncIterable<T>, op1: OperatorAsyncFunction<T, A>, op2: OperatorAsyncFunction<A, B>, op3: OperatorAsyncFunction<B, C>, op4: OperatorAsyncFunction<C, D>, op5: OperatorAsyncFunction<D, E>, op6: OperatorAsyncFunction<E, F>, op7: OperatorAsyncFunction<F, G>): AsyncIterableX<G>; | |
export function pipe<T, A, B, C, D, E, F, G, H>(source: AsyncIterable<T>, op1: OperatorAsyncFunction<T, A>, op2: OperatorAsyncFunction<A, B>, op3: OperatorAsyncFunction<B, C>, op4: OperatorAsyncFunction<C, D>, op5: OperatorAsyncFunction<D, E>, op6: OperatorAsyncFunction<E, F>, op7: OperatorAsyncFunction<F, G>, op8: OperatorAsyncFunction<G, H>): AsyncIterableX<H>; | |
export function pipe<T, A, B, C, D, E, F, G, H, I>(source: AsyncIterable<T>, op1: OperatorAsyncFunction<T, A>, op2: OperatorAsyncFunction<A, B>, op3: OperatorAsyncFunction<B, C>, op4: OperatorAsyncFunction<C, D>, op5: OperatorAsyncFunction<D, E>, op6: OperatorAsyncFunction<E, F>, op7: OperatorAsyncFunction<F, G>, op8: OperatorAsyncFunction<G, H>, op9: OperatorAsyncFunction<H, I>): AsyncIterableX<I>; | |
/* tslint:enable:max-line-length */ | |
export function pipe<TSource, TResult>( | |
source: AsyncIterable<TSource>, | |
...operations: OperatorAsyncFunction<TSource, TResult>[]): AsyncIterableX<TResult> { | |
if (operations.length === 0) { | |
return source as any; | |
} | |
if (operations.length === 1) { | |
return operations[0] as any; | |
} | |
const piped = (input: AsyncIterable<TSource>): AsyncIterableX<TResult> => { | |
return operations.reduce((prev: any, fn: OperatorAsyncFunction<TSource, TResult>) => fn(prev), input); | |
}; | |
return piped(source); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment