Skip to content

Commit 1e04600

Browse files
committed
update comments
1 parent 9b6e187 commit 1e04600

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

filtering.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ func Skip2[TIter Seq2X[T1, T2], T1, T2 any](
170170
// For example:
171171
//
172172
// if the input iterator yields 1 2 3 3 2 1, Distinct function will yield 1 2 3.
173+
//
174+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
173175
func Distinct[TIter SeqX[T], T comparable](iterator TIter) Iterator[T] {
174176
return func(yield func(T) bool) {
175177
yielded := map[any]bool{}
@@ -197,6 +199,8 @@ func Distinct[TIter SeqX[T], T comparable](iterator TIter) Iterator[T] {
197199
//
198200
// if the input iterator yields ("john", 20) ("anne", 21) ("john", 22)
199201
// DistinctV1 function will yield ("john", 20) ("anne", 21) because ("john", 22) has the same key as ("john", 20).
202+
//
203+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
200204
func DistinctV1[TIter Seq2X[T1, T2], T1 comparable, T2 any](iterator TIter) Iterator2[T1, T2] {
201205
return func(yield func(T1, T2) bool) {
202206
yielded := newDistinctor[T1]()
@@ -219,6 +223,7 @@ func DistinctV1[TIter Seq2X[T1, T2], T1 comparable, T2 any](iterator TIter) Iter
219223
}
220224

221225
// DistinctV2 is similar to DistinctV1, but it deduplicates by the second element of the 2-tuple.
226+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
222227
func DistinctV2[TIter Seq2X[T1, T2], T1 any, T2 comparable](iterator TIter) Iterator2[T1, T2] {
223228
return func(yield func(T1, T2) bool) {
224229
yielded := newDistinctor[T2]()
@@ -241,6 +246,7 @@ func DistinctV2[TIter Seq2X[T1, T2], T1 any, T2 comparable](iterator TIter) Iter
241246
}
242247

243248
// DistinctBy accepts a custom function to determine the deduplicate-key.
249+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
244250
func DistinctBy[TIter SeqX[T], T any, K comparable](
245251
iterator TIter,
246252
keySelector func(T) K,
@@ -266,6 +272,7 @@ func DistinctBy[TIter SeqX[T], T any, K comparable](
266272
}
267273

268274
// Distinct2By is an Iterator2 version of DistinctBy.
275+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
269276
func Distinct2By[TIter Seq2X[T1, T2], T1 any, T2 any, K comparable](
270277
iterator TIter,
271278
keySelector func(T1, T2) K,

ordering.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
// since iter.SliceElem([]int{2, 3, 1})) yields 2 3 1
1515
// then Order(iter.SliceElem([]int{2, 3, 1})) will yield 1 2 3
1616
// and Order(iter.SliceElem([]int{2, 3, 1}), true) will yield 3 2 1.
17+
//
18+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
1719
func Order[TIter SeqX[T], T cmp.Ordered](
1820
iterator TIter,
1921
desc ...bool,
@@ -39,6 +41,8 @@ func Order[TIter SeqX[T], T cmp.Ordered](
3941
// since iter.Map(map[string]int{"bob":2, "eve":3, "alice":1}) yields the 2-tuples in arbitrary order
4042
// then OrderV1(iter.Map(map[string]int{"bob":2, "eve":3, "alice":1})) will yield (alice, 1) (bob 2) (eve 3)
4143
// and OrderV1(iter.Map(map[string]int{"bob":2, "eve":3, "alice":1}), true) will yield (eve 3) (bob 2) (alice, 1).
44+
//
45+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
4246
func OrderV1[TIter Seq2X[T1, T2], T1 cmp.Ordered, T2 any](
4347
iterator TIter,
4448
desc ...bool,
@@ -59,6 +63,7 @@ func OrderV1[TIter Seq2X[T1, T2], T1 cmp.Ordered, T2 any](
5963
}
6064

6165
// OrderV2 is like OrderV1, but it sorts by the second element of the 2-tuples.
66+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
6267
func OrderV2[TIter Seq2X[T1, T2], T1 any, T2 cmp.Ordered](
6368
iterator TIter,
6469
desc ...bool,
@@ -78,6 +83,7 @@ func OrderV2[TIter Seq2X[T1, T2], T1 any, T2 cmp.Ordered](
7883
}
7984

8085
// OrderBy accepts a comparison function and returns a new iterator that yields elements sorted by the comparison function.
86+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
8187
func OrderBy[TIter SeqX[T], T any](
8288
iterator TIter,
8389
cmp func(T, T) int,
@@ -86,6 +92,7 @@ func OrderBy[TIter SeqX[T], T any](
8692
}
8793

8894
// Order2By is the Iterator2 version of OrderBy.
95+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
8996
func Order2By[TIter Seq2X[T1, T2], T1, T2 any](
9097
iterator TIter,
9198
cmp func(*Combined[T1, T2], *Combined[T1, T2]) int,
@@ -94,6 +101,7 @@ func Order2By[TIter Seq2X[T1, T2], T1, T2 any](
94101
}
95102

96103
// StableOrderBy is like OrderBy, but it uses a stable sort algorithm.
104+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
97105
func StableOrderBy[TIter SeqX[T], T any](
98106
iterator TIter,
99107
cmp func(T, T) int,
@@ -102,6 +110,7 @@ func StableOrderBy[TIter SeqX[T], T any](
102110
}
103111

104112
// StableOrder2By is like Order2By, but it uses a stable sort algorithm.
113+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
105114
func StableOrder2By[TIter Seq2X[T1, T2], T1, T2 any](
106115
iterator TIter,
107116
cmp func(*Combined[T1, T2], *Combined[T1, T2]) int,

sequence.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ func Sequence2[T1, T2 any](generator func() (T1, T2, bool)) Iterator2[T1, T2] {
159159
}
160160
}
161161

162+
// Reverse returns an iterator that yields the values of the input iterator in reverse order.
163+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
162164
func Reverse[TIter SeqX[T], T any](iterator TIter) Iterator[T] {
163165
return func(yield func(T) bool) {
164166
var buffer []T
@@ -179,6 +181,8 @@ func Reverse[TIter SeqX[T], T any](iterator TIter) Iterator[T] {
179181
}
180182
}
181183

184+
// Reverse2 is the Iterator2 version of Reverse function.
185+
// be careful, if this function is used on iterators that has massive amount of data, it might consume a lot of memory.
182186
func Reverse2[TIter Seq2X[T1, T2], T1, T2 any](iterator TIter) Iterator2[T1, T2] {
183187
return func(yield func(T1, T2) bool) {
184188
var buffer []*Combined[T1, T2]

0 commit comments

Comments
 (0)