≈ the.bay.news

Idea: Add dropLast(while:) to BidirectionalCollection

Swift Forums
Idea: Add dropLast(while:) to BidirectionalCollection
I often need to drop elements from the end of a sequence based on a condition (for example, trimming trailing whitespace or filtering out values). Currently Swift only offers drop(while:) to drop from the start of a collection, but no built-in symmetric method to drop from the end. Without it, developers resort to awkward workarounds, like reversing the collection or manual loops. For example: let arr = [1, 2, 3, 4, 5] let trimmed = Array(arr.reversed().drop(while: { $0 > 3 })).reversed() // tr...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.