Skip to content

Commit 08ca8e7

Browse files
committed
Use foldl and less silly init pattern
1 parent 1deede0 commit 08ca8e7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Data/Foldable.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ mconcat :: forall f m. (Foldable f, Monoid m) => f m -> m
7171
mconcat = foldl (<>) mempty
7272

7373
intercalate :: forall f m. (Foldable f, Monoid m) => m -> f m -> m
74-
intercalate sep xs = (foldr go { init: true, acc: mempty } xs).acc
74+
intercalate sep xs = (foldl go { init: true, acc: mempty } xs).acc
7575
where
76-
go x { init = init } | init = { init: false, acc: x }
77-
go x { acc = acc } = { init: false, acc: x <> sep <> acc }
76+
go { init = true } x = { init: false, acc: x }
77+
go { acc = acc } x = { init: false, acc: acc <> sep <> x }
7878

7979
and :: forall f. (Foldable f) => f Boolean -> Boolean
8080
and = foldl (&&) true

0 commit comments

Comments
 (0)