Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concat1 and concatMap1 #53

Closed
Icelandjack opened this issue May 10, 2017 · 3 comments
Closed

concat1 and concatMap1 #53

Icelandjack opened this issue May 10, 2017 · 3 comments

Comments

@Icelandjack
Copy link

Icelandjack commented May 10, 2017

Like #49 but I don't want to clutter.

I needed concatMap1 just now. Would people be against adding

concat1 :: Foldable1 f => f (NonEmpty a) -> NonEmpty a
concat1 = concatMap1 id

concatMap1 :: forall f a b. Foldable1 f => (a -> NonEmpty b) -> (f a -> NonEmpty b)
concatMap1 f = foldr1m h where

  h :: a -> Maybe (NonEmpty b) -> NonEmpty b
  h a Nothing  = f a
  h a (Just x) = f a <> x

Similar functions exist as comments in Data.Semigroup.Foldable:

concat1    :: Foldable1 t => t (Stream a) -> Stream a
concatMap1 :: Foldable1 t => (a -> Stream b) -> t a -> Stream b
@bucklereed
Copy link
Contributor

Aren't those just fold1 and foldMap1, specialised to NonEmpty a for the semigroup?

@Icelandjack
Copy link
Author

You're right and same with Stream examples since Foldable1 Stream.

Data.Foldable does include

concat :: Foldable t => t [a] -> [a]
concatMap :: Foldable f => (a -> [b]) -> (t a -> [b])

so it may be worth adding them still (but obviously not as important)

concat1 :: Foldable1 f1 => f1 (NonEmpty a) -> NonEmpty a
concat1 = fold1

concatMap1 :: Foldable1 f1 => (a -> NonEmpty b) -> (f1 a -> NonEmpty b)
concatMap1 = foldMap1

@RyanGlScott
Copy link
Collaborator

Foldable1 is now defined in base, and semigroupoids simply re-exports Foldable1 from base. As such, this issue isn't really in scope for semigroupoids anymore. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants