data NonEmpty a = NonEmpty a (Array a)
I completed the following exercise from PureScript by Example:
Write a Foldable instance for NonEmpty. Hint: reuse the Foldable instance for arrays.
instance foldableNonEmpty :: Foldable NonEmpty where foldr f acc (NonEmpty a as) = foldr f (f a acc) as foldl f acc nonEmpty = foldr (flip f) acc nonEmpty foldMap f (NonEmpty a as) = f a <> (foldMap f as)
Please critique my implementation. Can I do better?