
Hi M, Am Dienstag, den 16.02.2016, 23:02 -0800 schrieb M Farkas-Dyck:
I quietly posted this library to Hackage nearly a year ago, but lately learned that some seeking such a package had difficulty finding it, so i announce it now ☺
https://hackage.haskell.org/package/filtrable
class Functor f => Filtrable f where mapMaybe :: (a -> Maybe b) -> f a -> f b catMaybes :: f (Maybe a) -> f a filter :: (a -> Bool) -> f a -> f a
For laws, see docs on Hackage.
You might want to add laws in the style of If this is also a Foldable, then toList . mapMaybe f = mapMapybe f . toList toList . catMaybes = catMaybes . toList toList . filter f = filter f . toList which would fix the behavior quite tightly. I wonder if these laws (together with a “well behaved” Foldable) still allow any unexpected behavior. And also whether they follow from your laws (but I don’t think so; mapMaybe could do something mean such as duplicating elements if there is at least one Nothing in the result). Do you plan to add instances for all the other data structures in base that are filtrable? Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • https://www.joachim-breitner.de/ XMPP: nomeata@joachim-breitner.de • OpenPGP-Key: 0xF0FBF51F Debian Developer: nomeata@debian.org