judah / haskeline

A Haskell library for line input in command-line programs.
https://hackage.haskell.org/package/haskeline
BSD 3-Clause "New" or "Revised" License
221 stars 75 forks source link

Add `mapInputT_` #179

Open janmasrovira opened 1 year ago

janmasrovira commented 1 year ago

This PR adds a variation of mapInputT that only works on the unit type.

mapInputT_ :: (m () -> m ()) -> InputT m () -> InputT m ()
mapInputT_ f = InputT . mapReaderT (mapReaderT (mapReaderT
                                  (mapReaderT (mapReaderT f))))
                    . unInputT

Note that mapInputT_ cannot be implemented in terms of mapInputT because of the forall b quantifier inside the first argument of mapInputT. Thus, it makes sense to also export mapInputT_, since there are cases in which it can be useful.