Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5010 committed Feb 14, 2019
1 parent cff9dac commit 625e5b1
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 48 deletions.
2 changes: 1 addition & 1 deletion assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func HasItems(items ...interface{}) Assertion {
})
}

// HasItems checks that an observable produces the corresponding number of items.
// HasSize checks that an observable produces the corresponding number of items.
func HasSize(size int) Assertion {
return newAssertion(func(a *assertion) {
a.checkHasSize = true
Expand Down
10 changes: 4 additions & 6 deletions iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,19 @@ func (it *iteratorFromChannel) Next() (interface{}, error) {
}

func (it *iteratorFromSlice) Next() (interface{}, error) {
it.index = it.index + 1
it.index++
if it.index < len(it.s) {
return it.s[it.index], nil
} else {
return nil, errors.New(errors.EndOfIteratorError)
}
return nil, errors.New(errors.EndOfIteratorError)
}

func (it *iteratorFromRange) Next() (interface{}, error) {
it.current = it.current + 1
it.current++
if it.current <= it.end {
return it.current, nil
} else {
return nil, errors.New(errors.EndOfIteratorError)
}
return nil, errors.New(errors.EndOfIteratorError)
}

func newIteratorFromChannel(ch chan interface{}) Iterator {
Expand Down
3 changes: 2 additions & 1 deletion iterator_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package rxgo

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIteratorFromChannel(t *testing.T) {
Expand Down
60 changes: 30 additions & 30 deletions observable.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ type observable struct {
onErrorResumeNext ErrorToObservableFunction
}

// CheckHandler checks the underlying type of an EventHandler.
// CheckEventHandler checks the underlying type of an EventHandler.
func CheckEventHandler(handler handlers.EventHandler) Observer {
return NewObserver(handler)
}

// CheckHandler checks the underlying type of an EventHandler.
// CheckEventHandlers checks the underlying type of an EventHandler.
func CheckEventHandlers(handler ...handlers.EventHandler) Observer {
return NewObserver(handler...)
}
Expand Down Expand Up @@ -807,8 +807,8 @@ func (o *observable) AverageInt() Single {
for {
if item, err := it.Next(); err == nil {
if v, ok := item.(int); ok {
sum = sum + v
count = count + 1
sum += v
count++
} else {
out <- errors.New(errors.IllegalInputError, fmt.Sprintf("type: %t", item))
close(out)
Expand All @@ -831,14 +831,14 @@ func (o *observable) AverageInt() Single {
// AverageInt8 calculates the average of numbers emitted by an Observable and emits this average int8.
func (o *observable) AverageInt8() Single {
f := func(out chan interface{}) {
var sum int8 = 0
var count int8 = 0
var sum int8
var count int8
it := o.iterable.Iterator()
for {
if item, err := it.Next(); err == nil {
if v, ok := item.(int8); ok {
sum = sum + v
count = count + 1
sum += v
count++
} else {
out <- errors.New(errors.IllegalInputError, fmt.Sprintf("type: %t", item))
close(out)
Expand All @@ -861,14 +861,14 @@ func (o *observable) AverageInt8() Single {
// AverageInt16 calculates the average of numbers emitted by an Observable and emits this average int16.
func (o *observable) AverageInt16() Single {
f := func(out chan interface{}) {
var sum int16 = 0
var count int16 = 0
var sum int16
var count int16
it := o.iterable.Iterator()
for {
if item, err := it.Next(); err == nil {
if v, ok := item.(int16); ok {
sum = sum + v
count = count + 1
sum += v
count++
} else {
out <- errors.New(errors.IllegalInputError, fmt.Sprintf("type: %t", item))
close(out)
Expand All @@ -891,14 +891,14 @@ func (o *observable) AverageInt16() Single {
// AverageInt32 calculates the average of numbers emitted by an Observable and emits this average int32.
func (o *observable) AverageInt32() Single {
f := func(out chan interface{}) {
var sum int32 = 0
var count int32 = 0
var sum int32
var count int32
it := o.iterable.Iterator()
for {
if item, err := it.Next(); err == nil {
if v, ok := item.(int32); ok {
sum = sum + v
count = count + 1
sum += v
count++
} else {
out <- errors.New(errors.IllegalInputError, fmt.Sprintf("type: %t", item))
close(out)
Expand All @@ -921,14 +921,14 @@ func (o *observable) AverageInt32() Single {
// AverageInt64 calculates the average of numbers emitted by an Observable and emits this average int64.
func (o *observable) AverageInt64() Single {
f := func(out chan interface{}) {
var sum int64 = 0
var count int64 = 0
var sum int64
var count int64
it := o.iterable.Iterator()
for {
if item, err := it.Next(); err == nil {
if v, ok := item.(int64); ok {
sum = sum + v
count = count + 1
sum += v
count++
} else {
out <- errors.New(errors.IllegalInputError, fmt.Sprintf("type: %t", item))
close(out)
Expand All @@ -951,14 +951,14 @@ func (o *observable) AverageInt64() Single {
// AverageFloat32 calculates the average of numbers emitted by an Observable and emits this average float32.
func (o *observable) AverageFloat32() Single {
f := func(out chan interface{}) {
var sum float32 = 0
var count float32 = 0
var sum float32
var count float32
it := o.iterable.Iterator()
for {
if item, err := it.Next(); err == nil {
if v, ok := item.(float32); ok {
sum = sum + v
count = count + 1
sum += v
count++
} else {
out <- errors.New(errors.IllegalInputError, fmt.Sprintf("type: %t", item))
close(out)
Expand All @@ -981,14 +981,14 @@ func (o *observable) AverageFloat32() Single {
// AverageFloat64 calculates the average of numbers emitted by an Observable and emits this average float64.
func (o *observable) AverageFloat64() Single {
f := func(out chan interface{}) {
var sum float64 = 0
var count float64 = 0
var sum float64
var count float64
it := o.iterable.Iterator()
for {
if item, err := it.Next(); err == nil {
if v, ok := item.(float64); ok {
sum = sum + v
count = count + 1
sum += v
count++
} else {
out <- errors.New(errors.IllegalInputError, fmt.Sprintf("type: %t", item))
close(out)
Expand All @@ -1013,7 +1013,7 @@ func (o *observable) Max(comparator Comparator) OptionalSingle {
out := make(chan optional.Optional)
go func() {
empty := true
var max interface{} = nil
var max interface{}
it := o.iterable.Iterator()
for {
if item, err := it.Next(); err == nil {
Expand Down Expand Up @@ -1045,7 +1045,7 @@ func (o *observable) Min(comparator Comparator) OptionalSingle {
out := make(chan optional.Optional)
go func() {
empty := true
var min interface{} = nil
var min interface{}
it := o.iterable.Iterator()
for {
if item, err := it.Next(); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion observablecreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func isClosed(ch <-chan interface{}) bool {
return false
}

// Creates observable from based on source function. Keep it mind to call emitter.OnDone()
// Create observable from based on source function. Keep it mind to call emitter.OnDone()
// to signal sequence's end.
// Example:
// - emitting none elements
Expand Down
10 changes: 4 additions & 6 deletions observablecreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,11 @@ type statefulIterable struct {
}

func (it *statefulIterable) Next() (interface{}, error) {
it.count = it.count + 1
it.count++
if it.count < 3 {
return it.count, nil
} else {
return nil, rxerrors.New(rxerrors.EndOfIteratorError)
}
return nil, rxerrors.New(rxerrors.EndOfIteratorError)
}

func (it *statefulIterable) Value() interface{} {
Expand All @@ -280,12 +279,11 @@ type statelessIterable struct {
}

func (it *statelessIterable) Next() (interface{}, error) {
it.count = it.count + 1
it.count++
if it.count < 3 {
return it.count, nil
} else {
return nil, rxerrors.New(rxerrors.EndOfIteratorError)
}
return nil, rxerrors.New(rxerrors.EndOfIteratorError)
}

//func TestFromStatelessIterable(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion single.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newOptionalSingleFrom(opt optional.Optional) OptionalSingle {
return &s
}

// CheckHandler checks the underlying type of an EventHandler.
// CheckSingleEventHandler checks the underlying type of an EventHandler.
func CheckSingleEventHandler(handler handlers.EventHandler) SingleObserver {
return NewSingleObserver(handler)
}
Expand Down
4 changes: 2 additions & 2 deletions singleobserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type singleObserver struct {
done chan interface{}
}

// NewSinglesingleObserver constructs a new SingleObserver instance with default SingleObserver and accept
// NewSingleObserver constructs a new SingleObserver instance with default SingleObserver and accept
// any number of EventHandler
func NewSingleObserver(eventHandlers ...handlers.EventHandler) SingleObserver {
ob := singleObserver{}
Expand Down Expand Up @@ -120,7 +120,7 @@ func (o *singleObserver) OnError(err error) {
}
}

// OnDone terminates the SingleObserver's internal Observable
// Block terminates the SingleObserver's internal Observable
func (o *singleObserver) Block() (interface{}, error) {
o.disposedMutex.Lock()
disposed := o.disposed
Expand Down

0 comments on commit 625e5b1

Please sign in to comment.