Skip to content

Commit

Permalink
Add Stream[T] type alias with Go 1.24 generic alias support (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
destel authored Feb 2, 2025
1 parent b38495b commit 394334b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
gotest:
strategy:
matrix:
go-version: [1.21.x, 1.23.x]
go-version: [1.21.x, 1.23.x, 1.24.0-rc.2]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ func StreamUsers(ctx context.Context, query *mockapi.UserQuery) <-chan rill.Try[
}
```

**Note:** Starting from Go 1.24, thanks to generic type aliases, the return type of the `StreamUsers` function
can optionally be simplified to `rill.Stream[*mockapi.User]`

```go
func StreamUsers(ctx context.Context, query *mockapi.UserQuery) rill.Stream[*mockapi.User] {
...
}
```


## Go 1.23 Iterators
Starting from Go 1.23, the language added *range-over-function* feature, allowing users to define custom iterators
Expand Down
19 changes: 19 additions & 0 deletions wrap124.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build go1.24

package rill

// Stream is a type alias for a channel of [Try] containers.
// This alias is optional, but it can make the code more readable.
//
// Before:
//
// func StreamUsers() <-chan rill.Try[*User] {
// ...
// }
//
// After:
//
// func StreamUsers() rill.Stream[*User] {
// ...
// }
type Stream[T any] = <-chan Try[T]

0 comments on commit 394334b

Please sign in to comment.