You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#### Select (Function) - Different Type Transformation
72
+
73
+
The `Select`**function** transforms elements to a different type. It's a standalone function (not a method) because Go methods cannot have their own type parameters:
oldest, ok:= glinq.From(people).Max(func(a, b Person) int {
234
+
return a.Age - b.Age
235
+
})
236
+
// oldest = Person{Age: 30, Name: "Alice"}, ok = true
237
+
```
238
+
142
239
### Lazy Evaluation Demonstration
143
240
144
241
```go
@@ -151,36 +248,72 @@ result := glinq.Range(1, 1000000).
151
248
// Only ~6 elements processed, not a million!
152
249
```
153
250
154
-
## Supported Operations
251
+
## API Reference
252
+
253
+
glinq provides both **methods** (on `Stream[T]` interface) and **standalone functions**. Methods support method chaining, while functions are used when type parameters are needed.
155
254
156
-
### Creators
255
+
### Creator Functions
256
+
257
+
These functions create a new `Stream[T]`:
157
258
158
259
-`From[T any](slice []T) Stream[T]` - create Stream from slice
159
260
-`Empty[T any]() Stream[T]` - create empty Stream
160
261
-`Range(start, count int) Stream[int]` - create Stream of integers
161
262
-`FromMap[K, V](m map[K]V) Stream[KeyValue[K, V]]` - create Stream from map
162
263
163
-
### Operators
264
+
### Stream Methods (Operators)
265
+
266
+
These methods transform the Stream and return a new `Stream[T]`:
164
267
165
268
-`Where(predicate func(T) bool) Stream[T]` - filter by condition
166
-
-`Select[R any](mapper func(T) R) Stream[R]` - transform elements
269
+
-`Select(mapper func(T) T) Stream[T]` - transform elements to the same type
167
270
-`Take(n int) Stream[T]` - take first n elements
168
271
-`Skip(n int) Stream[T]` - skip first n elements
169
272
170
-
### Terminal Operations
273
+
### Stream Methods (Terminal Operations)
274
+
275
+
These methods materialize the Stream:
171
276
172
277
-`ToSlice() []T` - convert Stream to slice
278
+
-`Chunk(size int) [][]T` - split Stream into chunks of specified size
173
279
-`First() (T, bool)` - get first element
280
+
-`Last() (T, bool)` - get last element
174
281
-`Count() int` - count number of elements
175
282
-`Any(predicate func(T) bool) bool` - check if any element exists
176
283
-`All(predicate func(T) bool) bool` - check if all elements satisfy condition
177
284
-`ForEach(action func(T))` - execute action for each element
285
+
-`Min(comparator func(T, T) int) (T, bool)` - find minimum element using comparator (works with any type)
286
+
-`Max(comparator func(T, T) int) (T, bool)` - find maximum element using comparator (works with any type)
287
+
288
+
### Transformation Functions
289
+
290
+
These standalone functions transform Stream to different types:
291
+
292
+
-`Select[T, R any](s Stream[T], mapper func(T) R) Stream[R]` - transform elements to a different type (function version)
293
+
294
+
### Map Helper Functions
295
+
296
+
These functions work with `Stream[KeyValue[K, V]]`:
0 commit comments