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

Generalize unzip, perhaps #44

Open
treeowl opened this issue Sep 8, 2017 · 1 comment
Open

Generalize unzip, perhaps #44

treeowl opened this issue Sep 8, 2017 · 1 comment

Comments

@treeowl
Copy link

treeowl commented Sep 8, 2017

I don't know if this makes sense, but it should work at least for Of and (,). The constraints on f look scary, but they really boil down to f being a bifunctor that's a comonad in its second argument.

unzip :: (Monad m, Bifunctor f, Functor (f b), Comonad (f (a,b)))
      => Stream (f (a,b)) m r -> Stream (f a) (Stream (f b) m) r
unzip = loop where
  loop str = case str of
    Return r -> Return r
    Effect m -> Effect (liftM loop (lift m))
    Step f -> Step
                  . first fst
                  . extend (Effect . Step . first snd)
                  . fmap (Return . loop) $ f

I don't know if the extra laziness here will cause any performance problems. If it does, and if this idea is actually good for something, we can offer both versions. As with copy, we really only need the power of Extend, not of Comonad.

@andrewthad
Copy link
Contributor

This is no longer the official repo for streaming. Please continue discussion of this issue here.

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

2 participants