-
-
Notifications
You must be signed in to change notification settings - Fork 10
Simplify List.folds with Dict/Set/List insert to fromList #357
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
base: main
Are you sure you want to change the base?
Conversation
|
Hi @caseyWebb 👋 List.foldl Set.insert Set.empty items
--> Set.fromList itemsThis one sounds fine to me 👍 It would not replace a version with a lambda though which I guess would be nice, but that could be a future improvement. List.foldl (\a b -> Set.insert a b) Set.empty itemsDon't forget to add tests for this one. List.foldl Dict.insert Dict.empty items
--> Dict.fromList itemsThis one doesn't work, or rather, the original line doesn't compile, so we should not try to simplify it List.foldl (\x acc -> if condition x then Set.insert x acc else acc) Set.empty items
--> items |> List.filterMap condition |> Set.fromList
List.foldl (\x acc -> if condition x then Dict.insert x acc else acc) Dict.empty items
--> items |> List.filterMap condition |> Dict.fromListThese ones I don't think would be a good fit, because they're much slower. I tend to rewrite my code from the latter to the former when I need to crank out performance. Also, I think it should by In the future, don't hesitate to create an issue with the idea first to avoid you doing work on things that will not work out. But I sincerely hope you had fun building these anyway 😄 |
|
Thanks for the speedy reply! This is very much a quick and dirty proof of concept, still very incomplete (as noted by the bad |
… case, support lambdas in simple insert
|
Yanked the conditionals, fixed the Dict case, added support for lambdas 🎉 |
|
Sorry that I took a bit longer to reply this time. I think the code looks generally good, but I have noticed a few cases where the rule incorrectly applies a simplification. I've added those in this commit which you can cherry-pick. a98dc7c Feel free to decide that you'd like to stick to a simpler set of simplifications. All is fine by me, and I wanted to say I highly appreciate the work you've put in, thank you |
Replaces instances of