Opened 4 years ago

Closed 4 years ago

#8587 closed feature request (invalid)

Add operator <%>, or similar, as <%> = flip fmap

Reported by: bunimo Owned by:
Priority: normal Milestone:
Component: Prelude Version: 7.6.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Often, piping results through one function after another provides a good conceptual flow to the code. But when the functions are a mixture of monadic and pure, it can seem more convoluted than it actually is. For example, compare:

  a <- monadicResult
  let b = pureFunction2 . pureFunction 1 <$> a
  c <- monadicFunction1 b >>= monadicFunction2


c <- monadicFunction2 =<<
     monadicFunction1 =<<
     pureFunction2    <$>
     pureFunction1    <$>

But this reading from bottom-to-up seems backwards, especially considering monadic code is more traditionally top-to-bottom, left-to-right.

I'd like to propose adding a new operator

infixl 1 <%>
(<%>) :: Functor f => f a -> (a -> b) -> f b
(<%>) = flip fmap

so that the following can be written. It is obvious what the intent of the code is. There are no unnecessary temporary variables. It conforms to typical monadic code direction. It is visually pleasing.

c <- monadicResult    <%>
     pureFunction1    <%>
     pureFunction2    >>=
     monadicFunction1 >>=

Change History (1)

comment:1 Changed 4 years ago by monoidal

Resolution: invalid
Status: newclosed

Proposals to add new functions or instances should be discussed on the libraries mailing list first. Once you get approval, you can paste a link to the discussion here.

Note: See TracTickets for help on using tickets.