Hacker News new | ask | show | jobs
by porridgeraisin 1000 days 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
1 comments

This 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