diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-09-22 13:07:09 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-10-01 18:34:53 -0400 |
commit | e393f213f5ccff4fd6034d5294e51aa5a2720890 (patch) | |
tree | d1702cd7050a6bf071d225da192a6ba2aff75c0b | |
parent | 0bb02873eeeca41a64d26becb9057e988f444acd (diff) | |
download | haskell-e393f213f5ccff4fd6034d5294e51aa5a2720890.tar.gz |
Allow fusion with catMaybes (#18574)
Metric Decrease:
T18574
-rw-r--r-- | libraries/base/Data/Maybe.hs | 4 | ||||
-rw-r--r-- | libraries/base/changelog.md | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/libraries/base/Data/Maybe.hs b/libraries/base/Data/Maybe.hs index d54ebf1ae4..8c46cfba8b 100644 --- a/libraries/base/Data/Maybe.hs +++ b/libraries/base/Data/Maybe.hs @@ -256,8 +256,8 @@ listToMaybe = foldr (const . Just) Nothing -- >>> catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ] -- [1,3] -- -catMaybes :: [Maybe a] -> [a] -catMaybes ls = [x | Just x <- ls] +catMaybes :: [Maybe a] -> [a] +catMaybes = mapMaybe id -- use mapMaybe to allow fusion (#18574) -- | The 'mapMaybe' function is a version of 'map' which can throw -- out elements. In particular, the functional argument returns diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index eb1bbdff4a..e8ceab903b 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -32,6 +32,9 @@ * Add `MonadFix` and `MonadZip` instances for `Complex` * Add `Ix` instances for tuples of size 6 through 15 + + * `catMaybes` is now implemented using `mapMaybe`, so that it is both a "good + consumer" and "good producer" for list-fusion (#18574) ## 4.14.0.0 *TBA* * Bundled with GHC 8.10.1 |