aboutsummaryrefslogtreecommitdiff
path: root/src/Data/List
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-02-27 22:17:03 +0100
committerTom Smeding <tom@tomsmeding.com>2024-02-27 22:17:03 +0100
commitfc942fb8dfaad7614567f2dcbd9a911ffd474a06 (patch)
tree4ae17384d7959dbadd581925849582bee5815b5d /src/Data/List
parent307919760c58e037ec3260fcd0c3c7f7227fd7aa (diff)
Trees that explode
Diffstat (limited to 'src/Data/List')
-rw-r--r--src/Data/List/NonEmpty/Util.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Data/List/NonEmpty/Util.hs b/src/Data/List/NonEmpty/Util.hs
new file mode 100644
index 0000000..3a0e7f6
--- /dev/null
+++ b/src/Data/List/NonEmpty/Util.hs
@@ -0,0 +1,12 @@
+module Data.List.NonEmpty.Util where
+
+import Data.List.NonEmpty (NonEmpty(..))
+
+
+sconcatne :: Semigroup s => NonEmpty s -> s
+sconcatne = \(x :| xs) -> go x xs
+ where go a [] = a
+ go a (x : xs) = go (a <> x) xs
+
+foldMapne :: Semigroup s => (a -> s) -> NonEmpty a -> s
+foldMapne f = sconcatne . fmap f