From 2bd88b7d3113db37f64a3da500844cc44c969775 Mon Sep 17 00:00:00 2001 From: Denis Buzdalov Date: Mon, 19 Aug 2024 18:30:29 +0300 Subject: [PATCH] [ base ] Implement `Foldable` and `Traversable` for `Identity` --- CHANGELOG_NEXT.md | 2 ++ libs/base/Control/Monad/Identity.idr | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/CHANGELOG_NEXT.md b/CHANGELOG_NEXT.md index 61689f1c2..7acfab27b 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 2b201c7b6..e85e34528 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