-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Contrary to the doc comment, List#map might not return an array. #121
Comments
Nice catch. It's puzzling, I'll take a deeper look later to find out why it states so. |
Here's a bit puzzling in line 145 dry-monads/lib/dry/monads/list.rb Line 145 in ceb5cae
in the def map(&block)
if block
fmap(block)
else
value.map(&block)
end
end Is |
haven't looked into code yet but I'm pretty sure, yes, it's intentional. Think about it as two different methods |
Here's the part that I don't quite get. If there's no block given, then it code runs to the |
Looking at it again now, I think that's correct. When
This matches the return type annotation and test in the commit that added this (464b7ad).
|
@niksosf thanks for tracking this down, I believe you're correct, especially that this is what @flash-gordon wrote in the changelog |
Describe the bug
https://github.com/dry-rb/dry-monads/blob/master/lib/dry/monads/list.rb#L139 states:
However, this isn't true; when called with a block,
List#map
will return a List.It also conflicts with the
@return [List,Enumerator]
annotation.I expected the doc comment would be accurate and consistent.
Either the comment needs updating, or the method is working incorrectly.
To Reproduce
Output:
Expected behavior
I expected the output to be an array, like
["A", "B", "C"]
Your environment
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
Ubuntu 14.04.6 LTS
The text was updated successfully, but these errors were encountered: