diff options
author | Paavo <pparkkin@gmail.com> | 2020-03-14 13:59:39 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-03-17 07:38:48 -0400 |
commit | 5b632dad2e1d373606fe29f7eee0daf15641560f (patch) | |
tree | 6c18086cfd58a00c7b1d287a9d443a215e220119 | |
parent | 5800ebfeb2fe3e3ed985cdf08a66defea73db71d (diff) | |
download | haskell-5b632dad2e1d373606fe29f7eee0daf15641560f.tar.gz |
Add example for Data.Semigroup.diff
-rw-r--r-- | libraries/base/Data/Semigroup.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libraries/base/Data/Semigroup.hs b/libraries/base/Data/Semigroup.hs index 918351f62e..9a21b9a2ec 100644 --- a/libraries/base/Data/Semigroup.hs +++ b/libraries/base/Data/Semigroup.hs @@ -125,6 +125,21 @@ cycle1 :: Semigroup m => m -> m cycle1 xs = xs' where xs' = xs <> xs' -- | This lets you use a difference list of a 'Semigroup' as a 'Monoid'. +-- +-- >>> import Data.Semigroup +-- >>> let hello = diff "Hello, " +-- >>> appEndo hello "World!" +-- "Hello, World!" +-- >>> appEndo (hello <> mempty) "World!" +-- "Hello, World!" +-- >>> appEndo (mempty <> hello) "World!" +-- "Hello, World!" +-- >>> let world = diff "World" +-- >>> let excl = diff "!" +-- >>> print $ appEndo (hello <> (world <> excl)) mempty +-- "Hello, World!" +-- >>> print $ appEndo ((hello <> world) <> excl) mempty +-- "Hello, World!" diff :: Semigroup m => m -> Endo m diff = Endo . (<>) |