News for hackers. Stuff that matters.
Re:A generically typed pipe function in TypeScript by cercatrova on Sunday August 07, 2022 @01:04PM (#32377912)
What do people think of fp-ts?
Re:A generically typed pipe function in TypeScript by homami on Sunday August 07, 2022 @01:28PM (#32378073)
I fully recommend this. The fp-ts is quite readable for JavaScript. Combine it with io-ts and you have a robust way of handling user inputs:

    pipe(
      decoder.decode(req.body)
      , E.mapLeft(_ex => new InputValidationError(decoder.decode(req.body)))
      , RTE.fromEither
      , RTE.chain(handleInput)
      , RTE.match(
        error => {
          res.status(500);
          res.send(error)
        },
        result =>  {
          res.send(result)
        }
      )
    )(reader)
Re:A generically typed pipe function in TypeScript by upzylon on Sunday August 07, 2022 @01:13PM (#32377973)
That looks interesting, I hadn't heard of the project. Will definitely have a look at the library.

But it defines its pipe function the same way RXJS does, separately for any number of arguments:

  function pipe<A>(a: A): A
  function pipe<A, B>(a: A, ab: (a: A) => B): B
  function pipe<A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C
  function pipe<A, B, C, D>(a: A, ab: (a: A) => B, bc: (b: B) => C, cd: (c: C) => D): D
  ...
https://github.com/gcanti/fp-ts/blob/master/src/function.ts#...
Re:A generically typed pipe function in TypeScript by jackblemming on Sunday August 07, 2022 @02:47PM (#32378710)
> But it defines its pipe function the same way RXJS does, separately for any number of arguments

What’s the issue? This has been a common way to do this sort of thing since C++ template meta programming. Have you honestly ever broke the bounds?

Re:A generically typed pipe function in TypeScript by upzylon on Sunday August 07, 2022 @03:00PM (#32378838)
There isn't necessarily any issue with it besides maybe not being very maintainable. I just tried to find a generic solution for the fun of it
Re:A generically typed pipe function in TypeScript by l2cluster on Sunday August 07, 2022 @01:11PM (#32377959)
I really like it, but TypeScript syntax is a bit unreadable with it. I'm used to Scala which looks a lot cleaner with extension methods and collections being immutable by default.