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

CatQueue traverse implementation #51

Open
nadameu opened this issue Nov 28, 2024 · 1 comment
Open

CatQueue traverse implementation #51

nadameu opened this issue Nov 28, 2024 · 1 comment

Comments

@nadameu
Copy link

nadameu commented Nov 28, 2024

The traverse implementation of CatQueue iterates through every element twice.

Is this intended?

traverse f =
map (foldl snoc empty)
<<< foldl (\acc -> lift2 snoc acc <<< f) (pure empty)

@garyb
Copy link
Member

garyb commented Nov 29, 2024

I would imagine it's to preserve the order since foldl will reorder it (and foldl is being used because it makes the traversal stack safe), although maybe cons could be used instead to avoid the double pass. I'm not sure if there should be a preference for it to generally be cons or snoc constructed, it probably depends on the operations being run on it.

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