Skip to content

Translating (+) <$> (*2) <*> (+10) #1801

Answered by samhh
THOUSAND-SKY asked this question in Q&A
Discussion options

You must be logged in to vote

I think that example relies on the applicative instance for (->). fp-ts-std defines these instances, for which the following appears to behave equivalently:

import { pipe } from 'fp-ts/function'
import * as Fn from 'fp-ts-std/Function'
import * as Num from 'fp-ts-std/Number'

export const f = pipe(
  Fn.of(Num.add),
  Fn.ap(Num.multiply(2)),
  Fn.ap(Num.add(10)),
)

Here pure (+) translates to Fn.of(Num.add).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@THOUSAND-SKY
Comment options

Answer selected by THOUSAND-SKY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants