summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Grenrus <oleg.grenrus@iki.fi>2023-01-23 17:01:02 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-01-28 02:58:38 -0500
commit082b7d43ee4b8203dc9bca53e5e1f7a45c42eeb8 (patch)
treed409b3f48ce265ba24d5e92334ce0f24b2205356
parentb3a3534b6f75b34dc4db76e904e071485da6d5cc (diff)
downloadhaskell-082b7d43ee4b8203dc9bca53e5e1f7a45c42eeb8.tar.gz
Add Foldable1 Solo instance
-rw-r--r--libraries/base/Data/Foldable1.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/libraries/base/Data/Foldable1.hs b/libraries/base/Data/Foldable1.hs
index 2c3f87ef39..b0aefc1132 100644
--- a/libraries/base/Data/Foldable1.hs
+++ b/libraries/base/Data/Foldable1.hs
@@ -32,6 +32,7 @@ import Data.List.NonEmpty (NonEmpty (..))
import Data.Semigroup
(Dual (..), First (..), Last (..), Max (..), Min (..), Product (..),
Semigroup (..), Sum (..))
+import GHC.Tuple (Solo (..))
import Prelude
(Maybe (..), Monad (..), Ord, Ordering (..), id, seq, ($!), ($), (.),
(=<<), flip, const, error)
@@ -388,6 +389,14 @@ instance Foldable1 Complex where
-- 3+ tuples are not Foldable/Traversable
+instance Foldable1 Solo where
+ foldMap1 f (MkSolo y) = f y
+ toNonEmpty (MkSolo x) = x :| []
+ minimum (MkSolo x) = x
+ maximum (MkSolo x) = x
+ head (MkSolo x) = x
+ last (MkSolo x) = x
+
instance Foldable1 ((,) a) where
foldMap1 f (_, y) = f y
toNonEmpty (_, x) = x :| []