Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/<$> and fmapForum ↗

<$> and fmap

App Development3 posts338 viewsLast activity Dec 2021
IA
Ianw1OP
Dec 2021

Hi, newbie question, I have the following code which works but I’m not clear on what it is doing:

condObligation <- Some <$> create (fromSome paymentObligation)

where paymentObligation is an optional field on my template. Please could I get a steer on what <$> does and why it is needed. I have looked at the documentation which says it is a synonym for fmap but if I replace <$> with fmap I get an error. Is there a way to achieve the same result using fmap instead of <$> please? Thanks!

CO
cocreature
Dec 2021

The difference between fmap and <$> is that fmap is a regular function while <$> is an infix operator. so to use fmap here use it like you use a regular function:

condObligation <- fmap Some (create (fromSome paymentObligation))

Alternatively you can also turn any function into an infix operator by wrapping it in backticks:

condObligation <- Some `fmap` create (fromSome paymentObligation)

You can also go the other way around and wrap infix operators in parentheses to turn them into (prefix) function?d

condObligation <- (<$>) Some (create (fromSome paymentObligation))
IA
Ianw1
Dec 2021

Of course, that makes perfect sense, thank you.

← Back to Discussions