DEV Community

Discussion on: Pipeable Pattern Matching in Typescript

Collapse
 
skona27 profile image
Jakub Skoneczny

I don't quite get this part:

const optionMatching = (o: O.Option<string>) =>
  pipe(
    o,
    M.matchW('_tag')({
      Some: ({ value }) => 'Something: ' + value,
      None: () => 'Nothing',
    })
  )
Enter fullscreen mode Exit fullscreen mode

Why do we pass o through a pipe? It is not a function because later in assertion, we provide a O.some('data') as a parameter for optionMathing.

Collapse
 
stefano_regosa profile image
Stefano Regosa

you are right in fact it isn't !!!
if we look at the fp-ts pipe signature and all the types overload ... the first params is a Generic and doesn't have to be a function :

gcanti.github.io/fp-ts/modules/fun...

for this reason, we can pass the Option
gcanti.github.io/fp-ts/modules/Opt... as the first argument and then pipe its model inside the M.matchW('_tag')