diff --git a/rx/factory.go b/rx/factory.go index 835321c..afa0f65 100644 --- a/rx/factory.go +++ b/rx/factory.go @@ -398,8 +398,8 @@ func Range[T Numeric](iterator RangeIterator[T], opts ...Option[T]) Observable[T } // RangeNF creates an Observable that emits count sequential integers beginning -// at start, for non numeric types, which do contain a nominated Numeric member -func RangeNF[T NominatedField[T, O], O Numeric](iterator RangeIteratorNF[T, O], +// at start, for non numeric types, which do contain a nominated proxy Numeric member +func RangeNF[T ProxyField[T, O], O Numeric](iterator RangeIteratorPF[T, O], opts ...Option[T], ) Observable[T] { if err := iterator.Init(); err != nil { diff --git a/rx/factory_test.go b/rx/factory_test.go index 3cf503e..2ab4534 100644 --- a/rx/factory_test.go +++ b/rx/factory_test.go @@ -877,7 +877,7 @@ var _ = Describe("Factory", func() { }) }) - When("missing StepBy", func() { + When("missing By", func() { It("🧪 should: default to 1", func() { defer leaktest.Check(GinkgoT())() @@ -894,13 +894,13 @@ var _ = Describe("Factory", func() { }) }) - When("StepBy 2", func() { + When("By 2", func() { It("🧪 should: create observable", func() { defer leaktest.Check(GinkgoT())() obs := rx.Range(&rx.NumericRangeIterator[int]{ StartAt: 5, - StepBy: 2, + By: 2, Whilst: rx.LessThan(12), }) @@ -912,13 +912,13 @@ var _ = Describe("Factory", func() { }) }) - When("StepBy 2 and reverse StepBy", func() { + When("By 2 and reverse By", func() { It("🧪 should: create observable", func() { defer leaktest.Check(GinkgoT())() obs := rx.Range(&rx.NumericRangeIterator[int]{ StartAt: 11, - StepBy: -2, + By: -2, Whilst: rx.MoreThan(4), }) @@ -1012,7 +1012,7 @@ var _ = Describe("Factory", func() { }) }) - Context("custom range iterator with nominated field", func() { + Context("custom range iterator with proxy field", func() { When("positive count", func() { It("🧪 should: create observable", func() { // Test_Range @@ -1020,7 +1020,7 @@ var _ = Describe("Factory", func() { obs := rx.RangeNF(&widgetByIDRangeIterator{ StartAt: widget{id: 5}, - StepBy: widget{id: 1}, + By: widget{id: 1}, Whilst: widgetLessThan(widget{id: 8}), }) @@ -1037,16 +1037,16 @@ var _ = Describe("Factory", func() { }) }) - Context("NominatedRangeIterator", func() { + Context("ProxyRangeIterator", func() { When("positive count", func() { It("🧪 should: create observable", func() { // Test_Range defer leaktest.Check(GinkgoT())() - obs := rx.RangeNF(&rx.NominatedRangeIterator[widget, int]{ + obs := rx.RangeNF(&rx.ProxyRangeIterator[widget, int]{ StartAt: widget{id: 5}, - StepBy: widget{id: 1}, - Whilst: rx.LessThanNF(widget{id: 8}), + By: widget{id: 1}, + Whilst: rx.LessThanPF(widget{id: 8}), }) rx.Assert(context.Background(), obs, diff --git a/rx/iterable-range.go b/rx/iterable-range.go index ecdd91c..718980d 100644 --- a/rx/iterable-range.go +++ b/rx/iterable-range.go @@ -22,11 +22,6 @@ package rx // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -// type rangeIterableL[T any] struct { -// start, count NumVal -// opts []Option[T] -// } - type rangeIterable[T any] struct { start, count NumVal iterator RangeIterator[T] @@ -59,21 +54,21 @@ func (i *rangeIterable[T]) Observe(opts ...Option[T]) <-chan Item[T] { return next } -type rangeIterableNF[T NominatedField[T, O], O Numeric] struct { - iterator RangeIteratorNF[T, O] +type rangeIterablePF[T ProxyField[T, O], O Numeric] struct { + iterator RangeIteratorPF[T, O] opts []Option[T] } -func newRangeIterableNF[T NominatedField[T, O], O Numeric](iterator RangeIteratorNF[T, O], +func newRangeIterableNF[T ProxyField[T, O], O Numeric](iterator RangeIteratorPF[T, O], opts ...Option[T], ) Iterable[T] { - return &rangeIterableNF[T, O]{ + return &rangeIterablePF[T, O]{ iterator: iterator, opts: opts, } } -func (i *rangeIterableNF[T, O]) Observe(opts ...Option[T]) <-chan Item[T] { +func (i *rangeIterablePF[T, O]) Observe(opts ...Option[T]) <-chan Item[T] { option := parseOptions(append(i.opts, opts...)...) ctx := option.buildContext(emptyContext) next := option.buildChannel() @@ -113,7 +108,7 @@ func Count[T Numeric](count T) WhilstFunc[T] { type NumericRangeIterator[T Numeric] struct { StartAt T - StepBy T + By T Whilst WhilstFunc[T] zero T } @@ -126,11 +121,11 @@ func (i *NumericRangeIterator[T]) Init() error { return nil } -// Start should return the initial index value. If the StepBy has +// Start should return the initial index value. If the By value has // not been set, it will default to 1. func (i *NumericRangeIterator[T]) Start() (*T, error) { - if i.StepBy == 0 { - i.StepBy = 1 + if i.By == 0 { + i.By = 1 } if i.Whilst == nil { @@ -141,12 +136,12 @@ func (i *NumericRangeIterator[T]) Start() (*T, error) { } func (i *NumericRangeIterator[T]) Step() T { - return i.StepBy + return i.By } // Increment increments the index value func (i *NumericRangeIterator[T]) Increment(index *T) T { - *(index) += i.StepBy + *(index) += i.By return *(index) } @@ -157,14 +152,14 @@ func (i *NumericRangeIterator[T]) While(current T) bool { return i.Whilst(current) } -type NominatedRangeIterator[T NominatedField[T, O], O Numeric] struct { +type ProxyRangeIterator[T ProxyField[T, O], O Numeric] struct { StartAt T - StepBy T + By T Whilst WhilstFunc[T] zero T } -func (i *NominatedRangeIterator[T, O]) Init() error { +func (i *ProxyRangeIterator[T, O]) Init() error { if i.Whilst == nil { return RangeMissingWhilstError } @@ -172,11 +167,11 @@ func (i *NominatedRangeIterator[T, O]) Init() error { return nil } -// Start should return the initial index value. If the StepBy has +// Start should return the initial index value. If By has // not been set, a panic occurs -func (i *NominatedRangeIterator[T, O]) Start() (*T, error) { - if i.StepBy.Field() == 0 { - panic("bad step-by, can't be zero") +func (i *ProxyRangeIterator[T, O]) Start() (*T, error) { + if i.By.Field() == 0 { + panic("bad by value, can't be zero") } if i.Whilst == nil { @@ -188,12 +183,12 @@ func (i *NominatedRangeIterator[T, O]) Start() (*T, error) { return &index, nil } -func (i *NominatedRangeIterator[T, O]) Step() O { - return i.StepBy.Field() +func (i *ProxyRangeIterator[T, O]) Step() O { + return i.By.Field() } // Increment increments index value -func (i *NominatedRangeIterator[T, O]) Increment(index *T) *T { +func (i *ProxyRangeIterator[T, O]) Increment(index *T) *T { // This does look a bit strange but its a work around // for the fact that the instance of T is implemented with // non-pointer receivers and therefore can't make modifications @@ -205,24 +200,24 @@ func (i *NominatedRangeIterator[T, O]) Increment(index *T) *T { // index receives a pointer to a copy of itself, via Increment // and increments the copy. // - (*index).Inc(index, i.StepBy) + (*index).Inc(index, i.By) return index } // While defines a condition that must be true for the loop to // continue iterating. -func (i *NominatedRangeIterator[T, O]) While(current T) bool { +func (i *ProxyRangeIterator[T, O]) While(current T) bool { return i.Whilst(current) } -func LessThanNF[T NominatedField[T, O], O Numeric](until T) WhilstFunc[T] { +func LessThanPF[T ProxyField[T, O], O Numeric](until T) WhilstFunc[T] { return func(current T) bool { return current.Field() < until.Field() } } -func MoreThanNF[T NominatedField[T, O], O Numeric](until T) WhilstFunc[T] { +func MoreThanPF[T ProxyField[T, O], O Numeric](until T) WhilstFunc[T] { return func(current T) bool { return current.Field() > until.Field() } diff --git a/rx/observable-operator-groupby_test.go b/rx/observable-operator-groupby_test.go index 2c4c3e7..3258031 100644 --- a/rx/observable-operator-groupby_test.go +++ b/rx/observable-operator-groupby_test.go @@ -47,7 +47,7 @@ var _ = Describe("Observable operator", func() { count := 11 obs := rx.Range(&rx.NumericRangeIterator[int]{ StartAt: 0, - StepBy: 1, + By: 1, Whilst: rx.LessThan(count), }).GroupBy(length, func(item rx.Item[int]) int { return item.V % length @@ -96,7 +96,7 @@ var _ = Describe("Observable operator", func() { obs := rx.Range(&rx.NumericRangeIterator[int]{ StartAt: 0, - StepBy: 1, + By: 1, Whilst: rx.LessThan(count), }).GroupByDynamic(func(item rx.Item[int]) string { if item.V == 10 { @@ -163,7 +163,7 @@ var _ = Describe("Observable operator", func() { obs := rx.Range(&rx.NumericRangeIterator[int]{ StartAt: 0, - StepBy: 1, + By: 1, Whilst: rx.LessThan(count), }).GroupBy(length, func(_ rx.Item[int]) int { return 4 diff --git a/rx/types.go b/rx/types.go index 737f7b2..aad5524 100644 --- a/rx/types.go +++ b/rx/types.go @@ -149,13 +149,13 @@ type ( While(current T) bool } - NominatedField[T any, O Numeric] interface { + ProxyField[T any, O Numeric] interface { Field() O Inc(index *T, by T) *T Index(int) *T } - RangeIteratorNF[T NominatedField[T, O], O Numeric] interface { + RangeIteratorPF[T ProxyField[T, O], O Numeric] interface { Init() error // Start should return the initial index value Start() (*T, error) diff --git a/rx/util_test.go b/rx/util_test.go index 73e5ea9..31d518f 100644 --- a/rx/util_test.go +++ b/rx/util_test.go @@ -119,23 +119,24 @@ func (w widget) Index(i int) *widget { type widgetByIDRangeIterator struct { StartAt widget - StepBy widget + By widget Whilst func(current widget) bool + zero widget } func (i *widgetByIDRangeIterator) Init() error { return nil } -// Start should return the initial index value. If the StepBy has +// Start should return the initial index value. If the By value has // not been set, it will default to 1. func (i *widgetByIDRangeIterator) Start() (*widget, error) { - if i.StepBy.id == 0 { - i.StepBy = widget{id: 1} + if i.By.id == 0 { + i.By = widget{id: 1} } if i.Whilst == nil { - return &widget{}, rx.BadRangeIteratorError{} + return &i.zero, rx.BadRangeIteratorError{} } index := i.StartAt @@ -144,12 +145,12 @@ func (i *widgetByIDRangeIterator) Start() (*widget, error) { } func (i *widgetByIDRangeIterator) Step() int { - return i.StepBy.id + return i.By.id } // Increment returns a pointer to a new instance of with incremented index value func (i *widgetByIDRangeIterator) Increment(index *widget) *widget { - index.id += i.StepBy.id + index.id += i.By.id return index }