From 75d90701e1fea6080a41b73c7777ff55ae7a8063 Mon Sep 17 00:00:00 2001 From: kitamin <11195207+meian@users.noreply.github.com> Date: Sun, 30 Jan 2022 02:55:32 +0900 Subject: [PATCH 1/6] #67 Add orEmpty, isEmpty implements --- empty.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/empty.go b/empty.go index a3b75cf..8e0b8aa 100644 --- a/empty.go +++ b/empty.go @@ -11,6 +11,21 @@ func empty[T any]() Iterable[T] { return emptyIterable[T]{} } +func orEmpty[T any](itb Iterable[T]) Iterable[T] { + if itb == nil { + return empty[T]() + } + return itb +} + +func isEmpty[T any](itb Iterable[T]) bool { + if itb == nil { + return true + } + _, ok := itb.(emptyIterable[T]) + return ok +} + func (itb emptyIterable[T]) Iterator() Iterator[T] { return emptyIter[T]() } From 5e9f4fa78c5f9fb2ee9f8c8533ac1b7b863b4cde Mon Sep 17 00:00:00 2001 From: kitamin <11195207+meian@users.noreply.github.com> Date: Sun, 30 Jan 2022 03:03:42 +0900 Subject: [PATCH 2/6] #67 Apply isEmpty orEmpty --- concat.go | 6 +++--- distinct.go | 4 ++-- filter.go | 4 ++-- map.go | 4 ++-- range.go | 6 ++++++ repeat.go | 4 ++-- reverse.go | 4 ++-- skip.go | 8 ++++---- sort.go | 12 ++++++------ take.go | 8 ++++---- 10 files changed, 33 insertions(+), 27 deletions(-) diff --git a/concat.go b/concat.go index 0e540b3..cce00e0 100644 --- a/concat.go +++ b/concat.go @@ -17,13 +17,13 @@ type concatIterator[T any] struct { // itb2 := gcf.FromSlice([]int{4, 5, 6}) // itbc := gcf.Concat(itb1, itb2) func Concat[T any](itb1 Iterable[T], itb2 Iterable[T]) Iterable[T] { - if itb1 == nil && itb2 == nil { + if isEmpty(itb1) && isEmpty(itb2) { return empty[T]() } - if itb2 == nil { + if isEmpty(itb2) { return itb1 } - if itb1 == nil { + if isEmpty(itb1) { return itb2 } return &concatIterable[T]{itb1, itb2} diff --git a/distinct.go b/distinct.go index 0580f01..851a529 100644 --- a/distinct.go +++ b/distinct.go @@ -18,8 +18,8 @@ type distinctIterator[T comparable] struct { // // Currently, result order is determined, but on spec, is undefined. func Distinct[T comparable](itb Iterable[T]) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } // Because no change has with Distinct combined Distinct, original Iterable is returned if itbd, ok := itb.(*distinctIterable[T]); ok { diff --git a/filter.go b/filter.go index cd549a3..f95d56b 100644 --- a/filter.go +++ b/filter.go @@ -18,8 +18,8 @@ type filterIterator[T any] struct { // // If filterFunc is nil, returns original Iteratable. func Filter[T any](itb Iterable[T], filterFunc func(v T) bool) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } if filterFunc == nil { return itb diff --git a/map.go b/map.go index f943ad4..dc0bd48 100644 --- a/map.go +++ b/map.go @@ -18,7 +18,7 @@ type mapIterator[T any, R any] struct { // // If mapFunc is nil, return Iterable in zero value elements. func Map[T any, R any](itb Iterable[T], mapFunc func(v T) R) Iterable[R] { - if itb == nil { + if isEmpty(itb) { return empty[R]() } if mapFunc == nil { @@ -69,7 +69,7 @@ type flatMapIterator[T any, R any] struct { // // If mapFunc is nil, return empty Iterable. func FlatMap[T any, R any](itb Iterable[T], mapFunc func(v T) []R) Iterable[R] { - if itb == nil { + if isEmpty(itb) { return empty[R]() } if mapFunc == nil { diff --git a/range.go b/range.go index 0f1cfec..1afa09e 100644 --- a/range.go +++ b/range.go @@ -42,6 +42,12 @@ func Range[T constraints.Integer](start, end, step T) (Iterable[T], error) { if start == end { return FromSlice([]T{start}), nil } + if step > 0 && start > end { + return empty[T](), nil + } + if step < 0 && start < end { + return empty[T](), nil + } return &rangeIterable[T]{start, end, step}, nil } diff --git a/repeat.go b/repeat.go index 8f27156..7b3da18 100644 --- a/repeat.go +++ b/repeat.go @@ -66,8 +66,8 @@ type repeatIterableIterator[T any] struct { // // If count is 0 or negative, return Iterable with no element. func RepeatIterable[T any](itb Iterable[T], count int) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } if count < 1 { return empty[T]() diff --git a/reverse.go b/reverse.go index 66023c2..182c3c9 100644 --- a/reverse.go +++ b/reverse.go @@ -15,8 +15,8 @@ type reverseIterator[T any] struct { // itb := gcf.FromSlice([]int{1, 2, 3}) // itb = gcf.Reverse(itb) func Reverse[T any](itb Iterable[T]) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } // reverse in reverse is original Iterable. if itbr, ok := itb.(*reverseIterable[T]); ok { diff --git a/skip.go b/skip.go index 8cb2b39..7f716a3 100644 --- a/skip.go +++ b/skip.go @@ -19,8 +19,8 @@ type skipIterator[T any] struct { // // If count is 0 or negative, returns original Iterable. func Skip[T any](itb Iterable[T], count int) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } if count < 1 { return itb @@ -67,8 +67,8 @@ type skipWhileIterator[T any] struct { // // If whileFunc is nil, returns original Iterable. func SkipWhile[T any](itb Iterable[T], whileFunc func(v T) bool) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } if whileFunc == nil { return itb diff --git a/sort.go b/sort.go index 57ff652..e780e7f 100644 --- a/sort.go +++ b/sort.go @@ -60,8 +60,8 @@ func (s funcSorter[T]) Sort() { sort.Sort(s) } // itb := gcf.FromSlice([]int{1, 3, 2}) // itb = gcf.SortAsc(itb) func SortAsc[T constraints.Ordered](itb Iterable[T]) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } toSorter := func(s []T) sorter[T] { return ascSlice[T](s) } return &sortIterable[T]{itb, toSorter} @@ -72,8 +72,8 @@ func SortAsc[T constraints.Ordered](itb Iterable[T]) Iterable[T] { // itb := gcf.FromSlice([]int{1, 3, 2}) // itb = gcf.SortDesc(itb) func SortDesc[T constraints.Ordered](itb Iterable[T]) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } toSorter := func(s []T) sorter[T] { return descSlice[T](s) } return &sortIterable[T]{itb, toSorter} @@ -87,8 +87,8 @@ func SortDesc[T constraints.Ordered](itb Iterable[T]) Iterable[T] { // // The less function takes x element and y element, and returns true if x is less than y. func SortBy[T any](itb Iterable[T], less func(x, y T) bool) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } toSorter := func(s []T) sorter[T] { return funcSorter[T]{s, less} } return &sortIterable[T]{itb, toSorter} diff --git a/take.go b/take.go index 8436f5f..4fe2564 100644 --- a/take.go +++ b/take.go @@ -20,8 +20,8 @@ type takeIterator[T any] struct { // // If count is 0 or negative, returns empty Iterable. func Take[T any](itb Iterable[T], count int) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } if count < 1 { return empty[T]() @@ -75,8 +75,8 @@ type takeWhileIterator[T any] struct { // // If whileFunc is nil, returns original Iterable. func TakeWhile[T any](itb Iterable[T], whileFunc func(v T) bool) Iterable[T] { - if itb == nil { - return empty[T]() + if isEmpty(itb) { + return orEmpty(itb) } if whileFunc == nil { return itb From ea65aab60623729d8a49c9e6795dd768875a6575 Mon Sep 17 00:00:00 2001 From: kitamin <11195207+meian@users.noreply.github.com> Date: Sun, 30 Jan 2022 03:40:56 +0900 Subject: [PATCH 3/6] #67 Add testEmptyChain implements --- common_test.go | 11 +++++++++++ export_test.go | 6 ++++++ 2 files changed, 17 insertions(+) create mode 100644 export_test.go diff --git a/common_test.go b/common_test.go index 13699ce..714229c 100644 --- a/common_test.go +++ b/common_test.go @@ -24,3 +24,14 @@ func testBeforeAndAfter[T any](t *testing.T, itb gcf.Iterable[T]) { assert.Zero(it.Current()) }) } + +// testEmptyChain tests Iterable is emptyIterable when chained from emptyIterable. +// On function called with emptyIterable should be emptyIterable. +func testEmptyChain(t *testing.T, f func(itb gcf.Iterable[int]) gcf.Iterable[int]) { + t.Helper() + itbe := gcf.FromSlice([]int{}) + t.Run("is empty Iterable", func(t *testing.T) { + itb := f(itbe) + assert.True(t, gcf.IsEmptyIterable(itb), "%v", gcf.ToSlice(itb)) + }) +} diff --git a/export_test.go b/export_test.go new file mode 100644 index 0000000..92aa6f0 --- /dev/null +++ b/export_test.go @@ -0,0 +1,6 @@ +package gcf + +// IsEmptyIterable detects itb is emptyIterable. +func IsEmptyIterable[T any](itb Iterable[T]) bool { + return isEmpty(itb) +} From a4127f7c43a7e9651a9f3bdbdeabcc928590adf7 Mon Sep 17 00:00:00 2001 From: kitamin <11195207+meian@users.noreply.github.com> Date: Sun, 30 Jan 2022 13:34:07 +0900 Subject: [PATCH 4/6] #67 Apply testEmptyChain --- concat_test.go | 7 +++++++ distinct_test.go | 4 ++++ filter_test.go | 4 ++++ map_test.go | 8 ++++++++ range_test.go | 9 +++++++++ repeat_test.go | 14 ++++++++++++++ reverse_test.go | 4 ++++ skip_test.go | 8 ++++++++ slice_test.go | 8 ++++++++ sort_test.go | 12 ++++++++++++ take_test.go | 8 ++++++++ 11 files changed, 86 insertions(+) diff --git a/concat_test.go b/concat_test.go index 5311d91..726629a 100644 --- a/concat_test.go +++ b/concat_test.go @@ -74,6 +74,13 @@ func TestConcat(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3}) itb = gcf.Concat(itb, gcf.FromSlice([]int{4, 5, 6})) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.Concat(itb, gcf.FromSlice([]int{})) + }) + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.Concat(itb, nil) + }) } func ExampleConcat() { diff --git a/distinct_test.go b/distinct_test.go index abdaf21..930c4be 100644 --- a/distinct_test.go +++ b/distinct_test.go @@ -56,6 +56,10 @@ func TestDistinct(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3, 2, 4}) itb = gcf.Distinct(itb) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.Distinct(itb) + }) } func ExampleDistinct() { diff --git a/filter_test.go b/filter_test.go index 452ff5b..9d00697 100644 --- a/filter_test.go +++ b/filter_test.go @@ -63,6 +63,10 @@ func TestFilter(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3, 4}) itb = gcf.Filter(itb, func(v int) bool { return v%2 == 0 }) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.Filter(itb, func(v int) bool { return true }) + }) } func ExampleFilter() { diff --git a/map_test.go b/map_test.go index 8d28e0d..3960630 100644 --- a/map_test.go +++ b/map_test.go @@ -52,6 +52,10 @@ func TestMap(t *testing.T) { assert.Equal(tt.want, s) }) } + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.Map(itb, func(v int) int { return v }) + }) } func ExampleMap() { @@ -140,6 +144,10 @@ func TestFlatMap(t *testing.T) { return strings.Repeat("a", v) }) testBeforeAndAfter(t, itbs) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.FlatMap(itb, func(v int) []int { return []int{v, v, v} }) + }) } func ExampleFlatMap() { diff --git a/range_test.go b/range_test.go index 2c7b757..ebf4b36 100644 --- a/range_test.go +++ b/range_test.go @@ -139,6 +139,15 @@ func TestRange(t *testing.T) { testBeforeAndAfter(t, itb) itb, _ = gcf.Range(3, 1, -1) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + itb, _ = gcf.Range(1, 0, 1) + return itb + }) + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + itb, _ = gcf.Range(1, 2, -1) + return itb + }) } func ExampleRange() { diff --git a/repeat_test.go b/repeat_test.go index 523719e..fe91431 100644 --- a/repeat_test.go +++ b/repeat_test.go @@ -51,6 +51,13 @@ func TestRepeat(t *testing.T) { itb := gcf.Repeat(1, 3) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.Repeat(1, 0) + }) + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.Repeat(1, -1) + }) } func ExampleRepeat() { @@ -116,6 +123,13 @@ func TestRepeatIterable(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3}) itb = gcf.RepeatIterable(itb, 2) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.RepeatIterable(itb, 0) + }) + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.RepeatIterable(itb, -1) + }) } func ExampleRepeatIterable() { diff --git a/reverse_test.go b/reverse_test.go index 404d99b..b8830ff 100644 --- a/reverse_test.go +++ b/reverse_test.go @@ -49,6 +49,10 @@ func TestReverse(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3}) itb = gcf.Reverse(itb) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.Reverse(itb) + }) } func ExampleReverse() { diff --git a/skip_test.go b/skip_test.go index 85599e4..2e264ad 100644 --- a/skip_test.go +++ b/skip_test.go @@ -86,6 +86,10 @@ func TestSkip(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3}) itb = gcf.Skip(itb, 2) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.Skip(itb, 0) + }) } func ExampleSkip() { @@ -166,6 +170,10 @@ func TestSkipWhile(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3}) itb = gcf.SkipWhile(itb, func(v int) bool { return v < 2 }) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.SkipWhile(itb, func(v int) bool { return true }) + }) } func ExampleSkipWhile() { diff --git a/slice_test.go b/slice_test.go index 92ca8b0..f2e80b6 100644 --- a/slice_test.go +++ b/slice_test.go @@ -94,6 +94,10 @@ func TestFromSlice_pointer(t *testing.T) { itb := gcf.FromSlice([]*int{&i1, &i2, &i3}) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.FromSlice([]int{}) + }) } func TestFromSliceImmutable(t *testing.T) { @@ -142,6 +146,10 @@ func TestFromSliceImmutable(t *testing.T) { itb := gcf.FromSliceImmutable([]int{1, 2, 3}) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.FromSliceImmutable([]int{}) + }) } func TestToSlice(t *testing.T) { diff --git a/sort_test.go b/sort_test.go index b327002..e7639c3 100644 --- a/sort_test.go +++ b/sort_test.go @@ -78,6 +78,10 @@ func TestSortAsc(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3}) itb = gcf.SortAsc(itb) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.SortAsc(itb) + }) } func TestSortDesc(t *testing.T) { @@ -150,6 +154,10 @@ func TestSortDesc(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3}) itb = gcf.SortDesc(itb) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.SortDesc(itb) + }) } func TestSortBy(t *testing.T) { @@ -239,6 +247,10 @@ func TestSortBy(t *testing.T) { itb := gcf.FromSlice([]data{{1}, {2}, {3}}) itb = gcf.SortBy(itb, func(x, y data) bool { return x.v < y.v }) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.SortBy(itb, func(x, y int) bool { return true }) + }) } func FuzzSortAsc(f *testing.F) { diff --git a/take_test.go b/take_test.go index 6ad7707..776878d 100644 --- a/take_test.go +++ b/take_test.go @@ -86,6 +86,10 @@ func TestTake(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3}) itb = gcf.Take(itb, 2) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.Take(itb, 1) + }) } func ExampleTake() { @@ -166,6 +170,10 @@ func TestTakeWhile(t *testing.T) { itb := gcf.FromSlice([]int{1, 2, 3}) itb = gcf.TakeWhile(itb, func(v int) bool { return v < 2 }) testBeforeAndAfter(t, itb) + + testEmptyChain(t, func(itb gcf.Iterable[int]) gcf.Iterable[int] { + return gcf.TakeWhile(itb, func(v int) bool { return true }) + }) } func ExampleTakeWhile() { From e99fdaf4ce91fa0e2cda6fc2432bdb1afb3be96e Mon Sep 17 00:00:00 2001 From: kitamin <11195207+meian@users.noreply.github.com> Date: Sun, 30 Jan 2022 13:39:08 +0900 Subject: [PATCH 5/6] #67 Fix FlatMap test --- map_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/map_test.go b/map_test.go index 3960630..2270369 100644 --- a/map_test.go +++ b/map_test.go @@ -140,8 +140,8 @@ func TestFlatMap(t *testing.T) { } itb := gcf.FromSlice([]int{1, 2, 3, 4}) - itbs := gcf.Map(itb, func(v int) string { - return strings.Repeat("a", v) + itbs := gcf.FlatMap(itb, func(v int) []string { + return []string{strings.Repeat("a", v)} }) testBeforeAndAfter(t, itbs) From 95b74becaeec439fdeedeb642b873d22544a7b39 Mon Sep 17 00:00:00 2001 From: kitamin <11195207+meian@users.noreply.github.com> Date: Sun, 30 Jan 2022 15:42:24 +0900 Subject: [PATCH 6/6] #67 Reorder Sort test --- sort_test.go | 54 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/sort_test.go b/sort_test.go index e7639c3..e62af39 100644 --- a/sort_test.go +++ b/sort_test.go @@ -84,6 +84,14 @@ func TestSortAsc(t *testing.T) { }) } +func ExampleSortAsc() { + itb := gcf.FromSlice([]int{3, 6, 7, 1, 5, 6, 2, 4, 5}) + itb = gcf.SortAsc(itb) + fmt.Println(gcf.ToSlice(itb)) + // Output: + // [1 2 3 4 5 5 6 6 7] +} + func TestSortDesc(t *testing.T) { type args struct { itb gcf.Iterable[int] @@ -160,6 +168,14 @@ func TestSortDesc(t *testing.T) { }) } +func ExampleSortDesc() { + itb := gcf.FromSlice([]int{3, 6, 7, 1, 5, 6, 2, 4, 5}) + itb = gcf.SortDesc(itb) + fmt.Println(gcf.ToSlice(itb)) + // Output: + // [7 6 6 5 5 4 3 2 1] +} + func TestSortBy(t *testing.T) { type data struct{ v int } type args struct { @@ -253,7 +269,17 @@ func TestSortBy(t *testing.T) { }) } -func FuzzSortAsc(f *testing.F) { +func ExampleSortBy() { + type data struct{ v int } + itbi := gcf.FromSlice([]int{3, 6, 7, 1, 5, 6, 2, 4, 5}) + itb := gcf.Map(itbi, func(v int) data { return data{v} }) + itb = gcf.SortBy(itb, func(x, y data) bool { return x.v < y.v }) + fmt.Println(gcf.ToSlice(itb)) + // Output: + // [{1} {2} {3} {4} {5} {5} {6} {6} {7}] +} + +func FuzzSort(f *testing.F) { type data struct{ v byte } tests := [][]byte{ {1, 2, 3}, @@ -291,29 +317,3 @@ func FuzzSortAsc(f *testing.F) { } }) } - -func ExampleSortAsc() { - itb := gcf.FromSlice([]int{3, 6, 7, 1, 5, 6, 2, 4, 5}) - itb = gcf.SortAsc(itb) - fmt.Println(gcf.ToSlice(itb)) - // Output: - // [1 2 3 4 5 5 6 6 7] -} - -func ExampleSortDesc() { - itb := gcf.FromSlice([]int{3, 6, 7, 1, 5, 6, 2, 4, 5}) - itb = gcf.SortDesc(itb) - fmt.Println(gcf.ToSlice(itb)) - // Output: - // [7 6 6 5 5 4 3 2 1] -} - -func ExampleSortBy() { - type data struct{ v int } - itbi := gcf.FromSlice([]int{3, 6, 7, 1, 5, 6, 2, 4, 5}) - itb := gcf.Map(itbi, func(v int) data { return data{v} }) - itb = gcf.SortBy(itb, func(x, y data) bool { return x.v < y.v }) - fmt.Println(gcf.ToSlice(itb)) - // Output: - // [{1} {2} {3} {4} {5} {5} {6} {6} {7}] -}