diff --git a/CHANGELOG_NEXT.md b/CHANGELOG_NEXT.md index 61689f1c21..7acfab27b7 100644 --- a/CHANGELOG_NEXT.md +++ b/CHANGELOG_NEXT.md @@ -215,6 +215,8 @@ This CHANGELOG describes the merged but unreleased changes. Please see [CHANGELO * Export `System.Signal.signalCode` and `System.Signal.toSignal`. +* Added implementations of `Foldable` and `Traversable` for `Control.Monad.Identity` + #### Contrib * `Data.List.Lazy` was moved from `contrib` to `base`. diff --git a/libs/base/Control/Monad/Identity.idr b/libs/base/Control/Monad/Identity.idr index 2b201c7b6e..e85e34528b 100644 --- a/libs/base/Control/Monad/Identity.idr +++ b/libs/base/Control/Monad/Identity.idr @@ -24,6 +24,19 @@ public export Monad Identity where (Id x) >>= k = k x +public export +Foldable Identity where + foldr f init (Id x) = f x init + foldl f init (Id x) = f init x + null _ = False + foldlM f init (Id x) = f init x + toList (Id x) = [x] + foldMap f (Id x) = f x + +public export +Traversable Identity where + traverse f (Id x) = Id <$> f x + public export Show a => Show (Identity a) where showPrec d (Id x) = showCon d "Id" $ showArg x