Skip to content

Commit

Permalink
rename Enumerator
Browse files Browse the repository at this point in the history
  • Loading branch information
hsldymq committed Apr 4, 2024
1 parent a893989 commit a4757fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
6 changes: 0 additions & 6 deletions enumerable.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package handy

import "iter"

type Iterable[T any] interface {
Iter() iter.Seq[T]
}

type Enumerable[T any] interface {
Iterable[T]
Count() int
Expand Down
48 changes: 24 additions & 24 deletions enumerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import (
"iter"
)

func newEnumerator[TIter goiter.SeqX[T], T any](it TIter) *Enumerator[T] {
return &Enumerator[T]{
func newEnumerator[TIter goiter.SeqX[T], T any](it TIter) *enumerator[T] {
return &enumerator[T]{
iterator: goiter.Iterator[T](it),
}
}

type Enumerator[T any] struct {
type enumerator[T any] struct {
iterator goiter.Iterator[T]
}

func (e *Enumerator[T]) Iter() iter.Seq[T] {
func (e *enumerator[T]) Iter() iter.Seq[T] {
return e.iterator.Seq()
}

func (e *Enumerator[T]) Count() int {
func (e *enumerator[T]) Count() int {
return e.iterator.Count()
}

func (e *Enumerator[T]) Any(predicate func(T) bool) bool {
func (e *enumerator[T]) Any(predicate func(T) bool) bool {
for each := range e.iterator {
if predicate(each) {
return true
Expand All @@ -32,7 +32,7 @@ func (e *Enumerator[T]) Any(predicate func(T) bool) bool {
return false
}

func (e *Enumerator[T]) All(predicate func(T) bool) bool {
func (e *enumerator[T]) All(predicate func(T) bool) bool {
for each := range e.iterator {
if !predicate(each) {
return false
Expand All @@ -41,70 +41,70 @@ func (e *Enumerator[T]) All(predicate func(T) bool) bool {
return true
}

func (e *Enumerator[T]) Filter(predicate func(T) bool) Enumerable[T] {
func (e *enumerator[T]) Filter(predicate func(T) bool) Enumerable[T] {
return filter(e, predicate)
}

func (e *Enumerator[T]) Take(n int) Enumerable[T] {
func (e *enumerator[T]) Take(n int) Enumerable[T] {
return newEnumerator(goiter.Take(e.Iter(), n))
}

func (e *Enumerator[T]) TakeLast(n int) Enumerable[T] {
func (e *enumerator[T]) TakeLast(n int) Enumerable[T] {
return newEnumerator(goiter.TakeLast(e.Iter(), n))
}

func (e *Enumerator[T]) Skip(n int) Enumerable[T] {
func (e *enumerator[T]) Skip(n int) Enumerable[T] {
return newEnumerator(goiter.Skip(e.Iter(), n))
}

func (e *Enumerator[T]) SkipLast(n int) Enumerable[T] {
func (e *enumerator[T]) SkipLast(n int) Enumerable[T] {
return newEnumerator(goiter.SkipLast(e.Iter(), n))
}

func (e *Enumerator[T]) Distinct() Enumerable[T] {
func (e *enumerator[T]) Distinct() Enumerable[T] {
return distinct[T](e)
}

func (e *Enumerator[T]) DistinctBy(keySelector func(T) any) Enumerable[T] {
func (e *enumerator[T]) DistinctBy(keySelector func(T) any) Enumerable[T] {
return distinctBy(e, keySelector)
}

func (e *Enumerator[T]) Union(target Enumerable[T]) Enumerable[T] {
func (e *enumerator[T]) Union(target Enumerable[T]) Enumerable[T] {
return union(e, target)
}

func (e *Enumerator[T]) UnionBy(target Enumerable[T], keySelector func(T) any) Enumerable[T] {
func (e *enumerator[T]) UnionBy(target Enumerable[T], keySelector func(T) any) Enumerable[T] {
return unionBy(e, target, keySelector)
}

func (e *Enumerator[T]) Intersect(target Enumerable[T]) Enumerable[T] {
func (e *enumerator[T]) Intersect(target Enumerable[T]) Enumerable[T] {
return intersect(e, target)
}

func (e *Enumerator[T]) IntersectBy(target Enumerable[T], keySelector func(T) any) Enumerable[T] {
func (e *enumerator[T]) IntersectBy(target Enumerable[T], keySelector func(T) any) Enumerable[T] {
return intersectBy(e, target, keySelector)
}

func (e *Enumerator[T]) Except(target Enumerable[T]) Enumerable[T] {
func (e *enumerator[T]) Except(target Enumerable[T]) Enumerable[T] {
return except(e, target)
}

func (e *Enumerator[T]) ExceptBy(target Enumerable[T], keySelector func(T) any) Enumerable[T] {
func (e *enumerator[T]) ExceptBy(target Enumerable[T], keySelector func(T) any) Enumerable[T] {
return exceptBy(e, target, keySelector)
}

func (e *Enumerator[T]) SequenceEqual(target Enumerable[T]) bool {
func (e *enumerator[T]) SequenceEqual(target Enumerable[T]) bool {
return sequenceEqual[T](e, target)
}

func (e *Enumerator[T]) SequenceEqualBy(target Enumerable[T], keySelector func(T) any) bool {
func (e *enumerator[T]) SequenceEqualBy(target Enumerable[T], keySelector func(T) any) bool {
return sequenceEqualBy(e, target, keySelector)
}

func (e *Enumerator[T]) Concat(iterables ...Iterable[T]) Enumerable[T] {
func (e *enumerator[T]) Concat(iterables ...Iterable[T]) Enumerable[T] {
return concat(e, iterables...)
}

func (e *Enumerator[T]) OrderBy(cmp func(a, b T) int) Enumerable[T] {
func (e *enumerator[T]) OrderBy(cmp func(a, b T) int) Enumerable[T] {
return orderBy(e, cmp)
}

0 comments on commit a4757fd

Please sign in to comment.