Skip to content

Feature/flat map #5

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

carter-ya
Copy link

I also have another way of implementation:

// FlatMap returns a Stream that flattens the result of the given FlatMapFunc, which means it's a 1:N model.
func (s Stream) FlatMap(fn FlatMapFunc, opts ...Option) Stream {
	source := make(chan interface{})
	
	go func() {
		group := NewRoutineGroup()
		for item := range s.source {
			each := item
			group.Run(func() {
				otherStream := fn(each)
				for other := range otherStream.source {
					source <- other
				}
			})
		}
		group.Wait()
		close(source)
	}()
	
	return Range(source)
}

Ref: #4

@kevwan kevwan requested a review from Copilot March 22, 2025 08:35
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant