Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/rubyPublic

Add Enumerable#join_map for efficient map and join#13792

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
prateekkish wants to merge6 commits intoruby:master
base:master
Choose a base branch
Loading
fromprateekkish:feature/enumerable-join-map

Conversation

prateekkish
Copy link

Summary

This PR addsEnumerable#join_map method that combines mapping and joining operations in a single pass through the enumerable.

ImplementsFeature #21386

Motivation

The current pattern of.map { ... }.join(sep) is:

  • Repetitive across Ruby codebases
  • Inefficient due to intermediate array creation
  • Could be more idiomatic

Usage

# Basic usage[1,2,3].join_map(","){ |n|n *2}# => "2,4,6"# With objectsusers=[{name:"Alice"},{name:"Bob"}]users.join_map(", "){ |u|u[:name]}# => "Alice, Bob"# Default separator is empty string(1..3).join_map{ |n|n}# => "123"

Performance

Benchmarks show consistent 28-30% performance improvement:

Array Size | map{}.join (ms) | join_map (ms) | Improvement------------------------------------------------------------10         |          0.0015 |        0.0012 |       23.2%100        |          0.0123 |        0.0088 |       28.6%1000       |          0.1211 |        0.0866 |       28.5%10000      |          1.2275 |        0.8531 |       30.5%

I haven't committed the benchmark code, but please let me know if I should do that.

This method combines mapping and joining in a single enumerable traversal,avoiding the intermediate array creation that occurs with map{}.join.Performance benchmarks show 28-30% improvement over traditional approach.
@prateekkishprateekkishforce-pushed thefeature/enumerable-join-map branch from50eeb81 to157b5e6CompareJuly 5, 2025 07:38
@prateekkishprateekkish requested a review fromnobuJuly 5, 2025 07:50
@launchable-appLaunchable app

This comment has been minimized.

This ensures join_map behaves exactly like map{}.join by recursivelyjoining array elements returned by the block.
@prateekkishprateekkishforce-pushed thefeature/enumerable-join-map branch from0d64618 tocc8e46cCompareJuly 5, 2025 17:48
@prateekkish
Copy link
Author

@nobu I have made the changes requested, thanks for a prompt review. Could I request another one?

@prateekkishprateekkishforce-pushed thefeature/enumerable-join-map branch from7bdf007 to3733558CompareJuly 8, 2025 15:06
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nobunobuAwaiting requested review from nobu

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@prateekkish@nobu

[8]ページ先頭

©2009-2025 Movatter.jp