[ base ] Implement Foldable and Traversable for Identity

This commit is contained in:
Denis Buzdalov 2024-08-19 18:30:29 +03:00 committed by Justus Matthiesen
parent 60ddcd0e07
commit 2bd88b7d31
2 changed files with 15 additions and 0 deletions

View File

@ -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`.

View File

@ -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