ref: 13593bf35c35d09fc9e01c030d813c3de58a2fc8
parent: 43b5b3d01239be636c9156f078047c6c07db1e8e
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Mon Dec 18 11:12:48 EST 2023
Add more standard stuff.
--- a/lib/Data/Either.hs
+++ b/lib/Data/Either.hs
@@ -20,6 +20,14 @@
either f _ (Left a) = f a
either _ f (Right b) = f b
+isLeft :: forall a b . Either a b -> Bool
+isLeft (Left _) = True
+isLeft (Right _) = False
+
+isRight :: forall a b . Either a b -> Bool
+isRight (Left _) = False
+isRight (Right _) = True
+
instance forall a b . (Show a, Show b) => Show (Either a b) where
showsPrec p (Left a) = showParen (p>=appPrec1) (showString "Left " . showsPrec appPrec1 a)
showsPrec p (Right b) = showParen (p>=appPrec1) (showString "Right " . showsPrec appPrec1 b)
--- a/lib/Data/Monoid.hs
+++ b/lib/Data/Monoid.hs
@@ -2,11 +2,13 @@
import Primitives
import Control.Applicative
import Control.Monad
+import Data.Bool
import Data.Bounded
import Data.Function
import Data.Functor
import Data.List_Type
import Data.Ord
+import Data.Maybe_Type
import Data.Num
import Data.Semigroup
@@ -99,3 +101,53 @@
instance forall a . (Num a) => Monoid (Product a) where
mempty = Product 1
+
+---------------------
+
+newtype All = All Bool
+getAll :: All -> Bool
+getAll (All a) = a
+
+instance Semigroup All where
+ All a <> All b = All (a && b)
+
+instance Monoid All where
+ mempty = All True
+
+---------------------
+
+newtype Any = Any Bool
+getAny :: Any -> Bool
+getAny (Any a) = a
+
+instance Semigroup Any where
+ Any a <> Any b = Any (a || b)
+
+instance Monoid Any where
+ mempty = Any False
+
+---------------------
+
+newtype First a = First (Maybe a)
+getFirst :: forall a . First a -> Maybe a
+getFirst (First a) = a
+
+instance forall a . Semigroup (First a) where
+ a@(First (Just _)) <> _ = a
+ First Nothing <> a = a
+
+instance forall a . Monoid (First a) where
+ mempty = First Nothing
+
+---------------------
+
+newtype Last a = Last (Maybe a)
+getLast :: forall a . Last a -> Maybe a
+getLast (Last a) = a
+
+instance forall a . Semigroup (Last a) where
+ _ <> a@(Last (Just _)) = a
+ a <> Last Nothing = a
+
+instance forall a . Monoid (Last a) where
+ mempty = Last Nothing
--
⑨