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 consecutivePairs and pairwise #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Janiczek
Copy link
Contributor

@Janiczek Janiczek commented Jun 29, 2023

consecutivePairs : List a -> List ( a, a )
pairwise : (a -> a -> b) -> List a -> List b

consecutivePairs [ 1, 2, 3, 4 ]
--> [ ( 1, 2 ), ( 2, 3 ), ( 3, 4 ) ]

pairwise (-) [100, 10, 1]
--> [ 90, 9 ]

@gampleman
Copy link
Contributor

Not really sure that consecutivePairs is really worth the space is takes given that it's trivially pairwise Tuple.pair. I think there was some good wisdom in the design of the core libraries when map2 was preferred over Haskell's zip...

@Chadtech
Copy link
Collaborator

Do we have some use cases associated with these? @Janiczek did you run into anything recently that lead you to using functions like this

I like pairwise and I think I have been in the situation where I wanted that function.

But for consecutivePairs, my hunch is that no one wants (a, a) as the final step in whatever they are doing. Getting consecutive elements paired up is always an intermediate step in something bigger, so it isn't clear why it needs to be tupled up to begin with. Does that make sense?

@Janiczek
Copy link
Contributor Author

Makes sense! We can probably go without consecutivePairs. I was mostly copying the existing API of uniquePairs : List a -> List (a,a).

My hunch is that I run into the need for pairwise a few times a year. This PR was prompted by one of these but I can't remember what it was for 😂

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.

3 participants