diff options
author | Douglas Wilson <douglas.wilson@gmail.com> | 2017-10-25 19:05:30 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-10-25 19:05:31 -0400 |
commit | 4c06ccb71737b77a8165e888ad75417a425549dd (patch) | |
tree | 96d27cc3f3a0b6bce13d2d2ff8bf4ae1c73ac065 | |
parent | 2c23fff2e03e77187dc4d01f325f5f43a0e7cad2 (diff) | |
download | haskell-4c06ccb71737b77a8165e888ad75417a425549dd.tar.gz |
base: Enable listToMaybe to fuse via foldr/build
Test Plan: Consider whether this is a good idea.
Reviewers: austin, hvr, bgamari, nomeata
Reviewed By: bgamari, nomeata
Subscribers: nomeata, rwbarton, thomie
GHC Trac Issues: #14387
Differential Revision: https://phabricator.haskell.org/D4126
-rw-r--r-- | libraries/base/Data/Maybe.hs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/libraries/base/Data/Maybe.hs b/libraries/base/Data/Maybe.hs index d8aad53b9e..5f5d5ac910 100644 --- a/libraries/base/Data/Maybe.hs +++ b/libraries/base/Data/Maybe.hs @@ -228,9 +228,12 @@ maybeToList (Just x) = [x] -- >>> maybeToList $ listToMaybe [1,2,3] -- [1] -- -listToMaybe :: [a] -> Maybe a -listToMaybe [] = Nothing -listToMaybe (a:_) = Just a +listToMaybe :: [a] -> Maybe a +listToMaybe = foldr (const . Just) Nothing +{-# INLINE listToMaybe #-} +-- We define listToMaybe using foldr so that it can fuse via the foldr/build +-- rule. See #14387 + -- | The 'catMaybes' function takes a list of 'Maybe's and returns -- a list of all the 'Just' values. |