diff --git a/lib/funky/funky.go b/lib/funky/funky.go index 5a8e946..3b6d385 100644 --- a/lib/funky/funky.go +++ b/lib/funky/funky.go @@ -33,7 +33,6 @@ func (m *maybe[V]) Value() V { // Iterator type Iterator[V any] interface { - Maybe[V] Next() Maybe[V] } @@ -43,24 +42,15 @@ type sliceIt[V any] struct { } func SliceIterator[V any](sl []V) Iterator[V] { - return &sliceIt[V]{slice: sl} + return &sliceIt[V]{-1, sl} } func (it *sliceIt[V]) Next() Maybe[V] { - if it.IsNothing() { + if it.idx >= len(it.slice)-1 { return Nothing[V]() } - v := it.Value() it.idx++ - return Just(v) -} - -func (it *sliceIt[V]) IsNothing() bool { - return it.idx >= len(it.slice) -} - -func (it *sliceIt[V]) Value() V { - return it.slice[it.idx] + return Just(it.slice[it.idx]) } func Slice[V any](it Iterator[V]) []V {