presz
Joined 5 years ago
Karma
16
Submissions
15
Member since
Jul 15
Joined 5 years ago
type UserId = string & { readonly __tag: unique symbol };
In Python you can use `NewType` from the typing module: from typing import NewType
from uuid import UUID
UserId = NewType("UserId", UUID)Javascript can do some functional programming, but it's not Haskell or OCaml. If you try to use it like that it quickly becomes a big mess and one that is not performant at all. You want to do pure, functional programming? Then write Haskell, or Elm, or Purescript.
I'm saying this as someone that loves fp, but is trying to get rid of a considerable chunk of fp-ts on a big codebase at work.
As a wise man once said, don't fight the language. Doing this deviates from Javascript semantics. It's a hack that is not actually helping people learn fp.
Also, please, don't do monads in Javascript! Monads are a solution for pure languages to deal with effects. Javascript can just do effects as it is!