From 86d8874398a56ec626ed53fc89bcfe92adbc5ce4 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Mon, 23 Jan 2023 17:01:02 +0200 Subject: Add Foldable1 Solo instance (cherry picked from commit 082b7d43ee4b8203dc9bca53e5e1f7a45c42eeb8) --- libraries/base/Data/Foldable1.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'libraries') 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 :| [] -- cgit v1.2.1