Improve pattern for finite-length iterators in flat_map expansions #116
Labels
No labels
A-build
A-cli
A-core
A-design
A-edn
A-ffi
A-query
A-sdk
A-sdk-android
A-sdk-ios
A-sync
A-transact
A-views
A-vocab
P-Android
P-desktop
P-iOS
bug
correctness
dependencies
dev-ergonomics
discussion
documentation
duplicate
enhancement
enquiry
good first bug
good first issue
help wanted
hygiene
in progress
invalid
question
ready
size
speed
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: greg/mentat#116
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
There are a bunch of places where we want to turn a collection of tuples (like
Vec<(A, B, C)>
) into a flat iterator, likeA1, B1, C1, A2, B2, C2, ...
. The pattern we're using right now is to combineflat_map
andstd::iter::once
, like:That avoids heap allocation in favour of stack allocation, but gets pretty gnarly when the tuple length increases. For example:
64ff2efe01 (diff-54794907269c3b2d0bebbfd6a8aeab5dR617)
64ff2efe01 (diff-54794907269c3b2d0bebbfd6a8aeab5dR476)
This ticket tracks doing something better. Perhaps a few helper functions (like
once_2
andonce_3
?), orimpl (A, B) { fn once(...) { } }
, or a macro to at least make the callsite easier to read.This is probably not a good first bug unless you're strong in Rust, because some taste is required to determine what's better than the pattern we have now.