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

Add joining functions #131

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

joshgodsiff
Copy link

No description provided.

@@ -1 +1 @@
resolver: lts-7.14
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project was no-longer buildable under this, so I updated it to a fairly recent one.

{-| Join two 'Fold's by applying joining functions to their inputs and
outputs.
-}
joinWith :: (e -> a) -> (e -> c) -> (b -> d -> f) -> Fold a b -> Fold c d -> Fold e f
Copy link
Author

@joshgodsiff joshgodsiff Feb 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example: joinWith fst snd (,) will give you a Fold a b -> Fold c d -> Fold (a,c) (b,d)

@Gabriella439
Copy link
Owner

I don't think these joining functions are necessary because they can be implemented in terms of existing type class methods concisely. For example:

joinOutputsWith = liftA2

joinWith inL inR out foldL foldR = liftA2 out (lmap inL foldL) (lmap inR foldR)

I think there is something still worth adding, which is a utility of the following type:

postMapM :: (a -> m b) -> FoldM m i a -> FoldM m i b

... because then that would dmake joinOutputsWithM and joinWithM no longer necessary, too:

joinOutputsWithM f foldL foldR = postMapM id (liftA2 f foldL foldR)

joinWIthM inL inR out = postMapM id (liftA2 f (lmap inL foldL) (lmap inR folddR))

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

Successfully merging this pull request may close these issues.

2 participants