-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return Generator from slice and channel New functions
- Loading branch information
Showing
3 changed files
with
21 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
package generator | ||
|
||
// Channel implements `Generator` interface for channels. | ||
type Channel struct { | ||
channel <-chan interface{} | ||
value interface{} | ||
// channel implements `Generator` interface for channels. | ||
type channel struct { | ||
chn <-chan interface{} | ||
value interface{} | ||
} | ||
|
||
// NewChannel creates a new instance of `Channel` for `channel`. | ||
func NewChannel(channel <-chan interface{}) *Channel { | ||
return &Channel{channel, nil} | ||
// Newchannel creates a new instance of `Generator` for channels. | ||
func NewChannel(chn <-chan interface{}) Generator { | ||
return &channel{chn, nil} | ||
} | ||
|
||
// Next prepares a new element, and returns `false` at the end of iteration. | ||
func (g *Channel) Next() bool { | ||
func (g *channel) Next() bool { | ||
var ok bool | ||
g.value, ok = <-g.channel | ||
g.value, ok = <-g.chn | ||
return ok | ||
} | ||
|
||
// Value returns the value of prepared element. | ||
func (g *Channel) Value() interface{} { | ||
func (g *channel) Value() interface{} { | ||
return g.value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters