-
Notifications
You must be signed in to change notification settings - Fork 50
Complexity, Generalizations of Monadic Functions, and Code Reuse #35
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
Conversation
…e monadic functions to `Applicative`, reduce explicit recursion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this definitely still O(n)? It only is if the singletons are concatenated to the left of the result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it should be the same as the above functions using foldMap, since foldMap is right fold, and concatenation to the singleton should be constant time. It does feel like a fair amount of wrapping/unwrapping, perhaps it would be better to define mapMaybe (and use it for filter as well)?
|
Looks great! I added a couple of comments. |
src/Data/List.purs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure this will be a lot slower than the original definition - reconstructing the entire list and taking an element vs reading it once and taking the last element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hadn't been thinking of that. I'll try using a fold.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently TCO will optimise this, a fold will be slower too.
0794dbf to
3a94634
Compare
|
Sorry this has gone unmerged for so long. Would you be interested in rebasing this on top of |
|
Thanks! I'll split it up into smaller PRs. |
|
Ok thanks! I'll close this one then. |
findLastIndexreplicateMandfilterMtoApplicative