Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ReactiveX/v2
V2
- Loading branch information
Showing
16 changed files
with
1,322 additions
and
1,218 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module github.com/reactivex/rxgo | ||
|
||
require ( | ||
github.com/gorilla/websocket v1.4.0 | ||
github.com/stretchr/testify v1.3.0 | ||
) |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= | ||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package rxgo | ||
|
||
type Iterable interface { | ||
Iterator() Iterator | ||
} | ||
|
||
type iterableFromChannel struct { | ||
ch chan interface{} | ||
} | ||
|
||
type iterableFromSlice struct { | ||
s []interface{} | ||
} | ||
|
||
type iterableFromRange struct { | ||
start int | ||
count int | ||
} | ||
|
||
type iterableFromFunc struct { | ||
f func(chan interface{}) | ||
} | ||
|
||
func (it *iterableFromFunc) Iterator() Iterator { | ||
out := make(chan interface{}) | ||
go it.f(out) | ||
return newIteratorFromChannel(out) | ||
} | ||
|
||
func (it *iterableFromChannel) Iterator() Iterator { | ||
return newIteratorFromChannel(it.ch) | ||
} | ||
|
||
func (it *iterableFromSlice) Iterator() Iterator { | ||
return newIteratorFromSlice(it.s) | ||
} | ||
|
||
func (it *iterableFromRange) Iterator() Iterator { | ||
return newIteratorFromRange(it.start-1, it.start+it.count) | ||
} | ||
|
||
func newIterableFromChannel(ch chan interface{}) Iterable { | ||
return &iterableFromChannel{ | ||
ch: ch, | ||
} | ||
} | ||
|
||
func newIterableFromSlice(s []interface{}) Iterable { | ||
return &iterableFromSlice{ | ||
s: s, | ||
} | ||
} | ||
|
||
func newIterableFromRange(start, count int) Iterable { | ||
return &iterableFromRange{ | ||
start: start, | ||
count: count, | ||
} | ||
} | ||
|
||
func newIterableFromFunc(f func(chan interface{})) Iterable { | ||
return &iterableFromFunc{ | ||
f: f, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,6 +1,67 @@ | ||
package rxgo | ||
|
||
// Iterator type is implemented by Iterable. | ||
import "github.com/reactivex/rxgo/errors" | ||
|
||
type Iterator interface { | ||
Next() (interface{}, error) | ||
} | ||
|
||
type iteratorFromChannel struct { | ||
ch chan interface{} | ||
} | ||
|
||
type iteratorFromSlice struct { | ||
index int | ||
s []interface{} | ||
} | ||
|
||
type iteratorFromRange struct { | ||
current int | ||
end int // Included | ||
} | ||
|
||
func (it *iteratorFromChannel) Next() (interface{}, error) { | ||
if next, ok := <-it.ch; ok { | ||
return next, nil | ||
} | ||
|
||
return nil, errors.New(errors.EndOfIteratorError) | ||
} | ||
|
||
func (it *iteratorFromSlice) Next() (interface{}, error) { | ||
it.index = it.index + 1 | ||
if it.index < len(it.s) { | ||
return it.s[it.index], nil | ||
} else { | ||
return nil, errors.New(errors.EndOfIteratorError) | ||
} | ||
} | ||
|
||
func (it *iteratorFromRange) Next() (interface{}, error) { | ||
it.current = it.current + 1 | ||
if it.current <= it.end { | ||
return it.current, nil | ||
} else { | ||
return nil, errors.New(errors.EndOfIteratorError) | ||
} | ||
} | ||
|
||
func newIteratorFromChannel(ch chan interface{}) Iterator { | ||
return &iteratorFromChannel{ | ||
ch: ch, | ||
} | ||
} | ||
|
||
func newIteratorFromSlice(s []interface{}) Iterator { | ||
return &iteratorFromSlice{ | ||
index: -1, | ||
s: s, | ||
} | ||
} | ||
|
||
func newIteratorFromRange(start, end int) Iterator { | ||
return &iteratorFromRange{ | ||
current: start, | ||
end: end, | ||
} | ||
} |
Oops, something went wrong.