Skip to content

The values passed to the block parameter differ between map and uniq. #8435

@yamam

Description

@yamam

Environment Information

$ jruby -v
jruby 9.4.9.0 (3.1.4) 2024-11-04 547c6b150e OpenJDK 64-Bit Server VM 21.0.5+11-Ubuntu-1ubuntu124.04 on 21.0.5+11-Ubuntu-1ubuntu124.04 +jit [x86_64-linux]
$ uname -a
Linux       5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

In Ruby 3.3.6, the following two execution results are the same:

$ ruby -e '[[1,2],[3,4],[5,6]].each_with_index.uniq {|x| p x}'
[1, 2]
[3, 4]
[5, 6]
$ ruby -e '[[1,2],[3,4],[5,6]].each_with_index.map {|x| p x}'
[1, 2]
[3, 4]
[5, 6]

In JRuby 9.4.9.0, the following two execution results are different:

$ jruby -e '[[1,2],[3,4],[5,6]].each_with_index.uniq {|x| p x}'
[[1, 2], 0]
[[3, 4], 1]
[[5, 6], 2]
$ jruby -e '[[1,2],[3,4],[5,6]].each_with_index.map {|x| p x}'
[1, 2]
[3, 4]
[5, 6]

I thought the output of uniq in JRuby was correct, but which one is actually correct?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions