3 ms·
export const pipe = <A, B>(f: Fun<A, B>) => { return { to: <C>(g: Fun<B, C>) => pipe((arg: A) => g(f(arg))), build: () => f, };
by porridgeraisin 3y ago
export const pipe = <A, B>(f: Fun<A, B>) => {
return {
to: <C>(g: Fun<B, C>) => pipe((arg: A) => g(f(arg))),
build: () => f,
};
};
Much simpler alternative.
const process = pipe(readLines).to(x => cut(x, 2)).to(....).build()
const result = await process(fd)
P.S the Fun type is just (...args: A) => B
- jeroenhd 3y agoThis solution seems a lot cleaner to me syntactically, but it does lack helpers like .concat(). You'd have to write methods like .pipe( x => x + "!") to extend methods. Then again, prefixing and postfixing operaties shouldn't be too hard to write either
- porridgeraisin 3y agoI like https://github.com/WiseLibs/wise-river https://github.com/WiseLibs/wise-river For complex uses