From fc942fb8dfaad7614567f2dcbd9a911ffd474a06 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 27 Feb 2024 22:17:03 +0100 Subject: Trees that explode --- src/Data/List/NonEmpty/Util.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/Data/List/NonEmpty/Util.hs (limited to 'src/Data/List/NonEmpty') 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 -- cgit v1.2.3-70-g09d2