-
Notifications
You must be signed in to change notification settings - Fork 336
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
Cold observable #158
Cold observable #158
Conversation
Pull Request Test Coverage Report for Build 299
💛 - Coveralls |
# Conflicts: # iterable/iterable_test.go # observable_test.go
Thanks @teivah for the effort! Is there a reason for having separate for {
if v, ok := it.Next(); ok {
// Do something with v
} else {
fmt.Println("End of iterator")
break
}
} The decision to implement |
@jochasinga Hi, nice to discuss with you :) Actually, I did it because from my perspective it was even more idiomatic ^^ As a concrete example, taken from Go standard library:
So, to iterate over a for myScanner.Scan() {
value := myScanner.Text()
fmt.Println(value)
} But obviously this is not that important. If you prefer to keep it as you initially proposed, I can change it. |
The In Python, a generator implements a In JS however, an iterator Same goes with In addition, I think a method IMHO I'm a fan of if val, err := iter.Next(); err != nil {
// ...
} than returning a cc @avelino |
Okay I see the potential benefit. I did a rollback to use the previous |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found some fixes!
P.S. share your ideas, feedbacks or issues with us at https://github.com/fixmie/feedback (this message will be removed after the beta stage).
@avelino Ready for 2019! 😄 |
A first implementation of cold observables.
First, I changed the few things:
Iterator
remains an interface but proposes two methodsNext() bool
andValue() interface{}
. No real difference here but just a more idiomatic way to iterate on a structure, in my opinion.Iterable
became an interface with only oneIterator() Iterator
method.Observable
became an interface with a list of operators but is also composed ofIterable
.To iterate over an
Observable
, every operator is doing it this way:Then, I tried to respect two approaches:
For example, let's check at the
Map
operator implementation:Instead of creating a goroutine once the operator is called, we wrap a function within the
Observable
returned.When did this function trigger? Basically, during a subscription to the
Observable
. This allows to reproduce the lazy behavior of coldObservable
and to keep the initial idea of managing pipelines between goroutines.One unit test is worth thousand words:
@avelino Please review this one before #157