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

Strict folds #21

Open
konsumlamm opened this issue Jun 6, 2020 · 2 comments
Open

Strict folds #21

konsumlamm opened this issue Jun 6, 2020 · 2 comments

Comments

@konsumlamm
Copy link
Collaborator

There are currently no strict fold operations (except for the Foldable instances ofc) in this package. Would it be worthwhile to add strict variants of the different folds that are provided (like foldrU, foldlU)? Or is there any particular reason to not include them?

Regarding the implementation, they could just be implemented like the default definitions of foldr' and foldl'.

@treeowl
Copy link
Collaborator

treeowl commented Dec 7, 2021

Yes. For min-queues, we want foldlAsc' and foldrDesc'. For max-queues, we want foldlDesc' and foldrAsc'. For all queues, we want foldlU' and possibly foldrU'. (Of course, we'll also want the WithKey versions.)

The current documentation for the unordered folds makes it pretty silly to have both left and right-handed versions. Obeying the documentation, we could define foldlWithKeyU f = foldrWithKeyU (\k a b -> f b k a). We really should either:

  1. Have foldrU and foldlU' only, or
  2. Have all the unordered folds, but document a specific relationship between the orderings they use. For example, we might want to specify that reverse . foldrU (:) [] = foldlU (flip (:)) []. I think I prefer this option.

@konsumlamm
Copy link
Collaborator Author

foldlU' was added in #59, so for unordered folds, this now has been addressed.

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

No branches or pull requests

2 participants