summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libraries/base/Data/Semigroup.hs15
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 . (<>)