Skip to content
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

Add Generate() function for ergonomic stream creation #42

Merged
merged 14 commits into from
Nov 24, 2024
Merged

Conversation

destel
Copy link
Owner

@destel destel commented Nov 24, 2024

Adds a new Generate function that simplifies stream creation by:

  • Removing channel/goroutine boilerplate
  • Providing ergonomic send/sendErr callbacks
  • Managing channel lifecycle automatically

Before:

stream := make(chan rill.Try[int])
go func() {
	defer close(stream)
	for i := 0; i < 100; i++ {
		stream <- rill.Try[int]{Value: i}
	}
	stream <- rill.Try[int]{Error: someError}
}()

After:

stream := rill.Generate(func(send func(int), sendErr func(error)) {
	for i := 0; i < 100; i++ {
		send(i)
	}
	sendErr(someError)
})

@destel destel added the new label Nov 24, 2024
Copy link

codecov bot commented Nov 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.11%. Comparing base (514ea1c) to head (a593797).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
+ Coverage   99.10%   99.11%   +0.01%     
==========================================
  Files          17       17              
  Lines        1002     1015      +13     
==========================================
+ Hits          993     1006      +13     
  Misses          9        9              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@destel destel merged commit 3d0ba14 into main Nov 24, 2024
5 checks passed
@destel destel deleted the f/generate branch November 24, 2024 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant