3 ms·
I was pleasantly surprised how far the type system goes though. Thanks to structural typing I get the pipe operator even for things I do not declare as SignalTr
by tlarkworthy 11y ago
I was pleasantly surprised how far the type system goes though. Thanks to structural typing I get the pipe operator even for things I do not declare as SignalTransformers in the following:
interface SignalFn<T> {
(time: number): T;
}
interface SignalTransformer<A, B>{
(a: SignalFn<A>): SignalFn<B>
}
// the >>> function
function pipe<A,B,C> (a: SignalTransformer<A,B>, b: SignalTransformer<B,C>): SignalTransformer<A,C> {
return (x: SignalFn<A>) => b(a(x))
}
// the arr lift
function lift<A, B>(fn: Function1<A,B>): SignalTransformer<A,B> {
return (input: SignalFn<A>) => <SignalFn<B>>((time: Time) => fn(input(time)));
}