Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #672 +/- ##
=======================================
Coverage 94.51% 94.51%
=======================================
Files 18 18
Lines 3429 3429
=======================================
Hits 3241 3241
Misses 174 174
Partials 14 14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I've had a lot of issues getting unit tests passing reliably due to timing dependencies in the channel/concurrency/retry tests - nothing to do with the specific changes introduced in this PR. |
|
Hey @NathanBaulch A big thank you for this work. 👏
I wonder if it could be useful to duplicate some helpers to receive/return If we do such a variant, we have to think about the meaning of the Anyway, 2 more helpers would be nice: Other proposal: add a I just figured out that May I suggest "it"? Any idea? No need to create examples on https://play.golang.org/. First, because we need to merge+release this contribution before, but also because I made an MCP server for creating all of them in 1 prompt. I think it's time for me to create a dedicated website for documentation. Mixing basic helpers with mutable, parallel, and iterable helpers will make this README.md unreadable. FYI, I will be releasing a reactive programming lib very soon (next week?), with an API similar to rxjs. The API will be very different and stream-oriented (eg: |
638f431 to
1e67376
Compare
Just to clarify, you're saying I should implement
Heh, where was this sentence going?
Would we need two versions of
I would propose |
Yes. Some helpers you built scan the full sequence as well. I would consider that developers understand that reversing a lazily produced slice is not possible without reading it 100%.
I don't remember 😅
Oh yes, definitely.
Perfect! |
I just realized that I haven't explained how I decided which full-scan helpers to exclude. It's basically about memory - I skipped the ones that need to scan the full sequence into a slice internally. So func Reverse[T any, I ~func(func(T) bool)](collection I) I {
s := slices.Collect(iter.Seq[T](collection))
mutable.Reverse(s)
return I(slices.Values(s))
}Anyway, happy to add them with a suitable disclaimer in the docs. |
|
Pretty sure I've addressed all outstanding feedback - time for an update!
|
|
Documentation is available here: https://lo.samber.dev/docs/iter/map The runnable examples will be published on Go playground tomorrow or on Wednesday. |


I finally got around to implementing iter support, as discussed last year in #439. This turned into a pretty big task, with over 160 new helper functions based on existing slice oriented helpers in the
itersub-package! ✨Implementation notes:
Isuffix convention used in themutablepackage for helper callbacks that include an index parameter.Difference,FilterReject,Unzip*not supported - no reasonable way to fan-out to multiple sequences.Reverse,ReduceRightnot supported - would need to buffer entire sequence.Sample*,Shufflenot supported - sequence length is unknown and no way to seek randomly forwards/backwards.OmitBy*,PickBy*not supported - picking/omitting from a map based on a sequence of keys/values doesn't seem useful.Wordsnot supported - not worthwhile with the current regex approach which appears to be intended for splitting relatively small identifiers.DropByIndex,Subset,*Nth*,Splicedon't support negative indexes.GroupBy,PartitionBy,Modereturn slices - they already have to scan the full input sequence.Chunkreturns a sequence of slices - feels awkward returning a sequence of sequences. Can we reuse the allocated slice?FindUniques*is implemented but needs to fully iterate the input sequence before yielding anything - not sure if reasonable.FindDuplicates*yields items in order of the first duplicate - this order differs slightly from the slice version.Fillis implemented but the name feels misleading - there's no pre-allocated memory being "filled".DropByIndex,WithoutNthare identical - the only difference to the slice version isDropByIndexsupports negative indexes.DropRightallocates an internal buffer slice of size n.DropRightWhileallocates an internal buffer slice that grows to the longest sub-sequence of items for which the predicate returns true.iter.Seq2and do not uselo.Entry- more idiomatic.Entries,ToPairs,FromEntries,FromPairsaccept multiple variadic inputs similar toKeysandValues- otherwise these helpers wouldn't offer any benefit overmaps.Allandmaps.Collect.lo.Sum- will block forever.slices.Collect.intorconstraints.Integereverywhere even if negative arguments are not supported.