# \#sequence

**URL:** https://forums.swift.org/tag/sequence/803.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [Are there continuations for synchronous code?](https://forums.swift.org/t/are-there-continuations-for-synchronous-code/79628)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 15\
**Last updated:** [May 4, 2025, 9:07am UTC](https://forums.swift.org/t/are-there-continuations-for-synchronous-code/79628 "2025-05-04T09:07:56Z")

</div>

Specifically, I want an iterator for a container that would be better using a yielding interface. I just discovered the AsyncStream generic type that lets sources yield their elements upstream. The problem is that AsyncS…

---

## [A sequence that deduplicates an already-sorted sequence](https://forums.swift.org/t/a-sequence-that-deduplicates-an-already-sorted-sequence/79611)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 0\
**Last updated:** [May 1, 2025, 3:40am UTC](https://forums.swift.org/t/a-sequence-that-deduplicates-an-already-sorted-sequence/79611 "2025-05-01T03:40:57Z")

</div>

I already wrote the code, made a pull request, then added an issue. I'm writing a Set-like type for Swift.Collections, and I want to deduplicate the data from a bulk-element initializer before building the binary tree i…

---

## [When could a sequence that doesn't use bulk storage for its elements implement \`withContiguousStorageIfAvailable\` anyway?](https://forums.swift.org/t/when-could-a-sequence-that-doesnt-use-bulk-storage-for-its-elements-implement-withcontiguousstorageifavailable-anyway/78643)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 1\
**Last updated:** [March 19, 2025, 8:29am UTC](https://forums.swift.org/t/when-could-a-sequence-that-doesnt-use-bulk-storage-for-its-elements-implement-withcontiguousstorageifavailable-anyway/78643 "2025-03-19T08:29:09Z")

</div>

From the documentation for Sequence.withContiguousStorageIfAvailable(\_:) This method calls body(buffer), where buffer is a pointer to the collection’s contiguous storage. If the contiguous storage doesn’t exist, the co…

---

## [Who calls the secret \`Sequence\` methods?](https://forums.swift.org/t/who-calls-the-secret-sequence-methods/78428)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 1\
**Last updated:** [March 11, 2025, 7:42am UTC](https://forums.swift.org/t/who-calls-the-secret-sequence-methods/78428 "2025-03-11T07:42:46Z")

</div>

This is about the 3 secret requirements for Sequence: \_copyContents(initializing:), \_copyToContiguousArray(), and \_customContainsEquatableElement(\_:). The third method is called by Sequence.contains(\_:). But my searchin…

---

## [Sequence is not a protocol?](https://forums.swift.org/t/sequence-is-not-a-protocol/75721)

<div class="topic-metadata">

**Author:** [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Replies:** 1\
**Last updated:** [October 31, 2024, 12:47am UTC](https://forums.swift.org/t/sequence-is-not-a-protocol/75721 "2024-10-31T00:47:07Z")

</div>

Since LazySequenceProtocol doesn't have a primary associated type, instead of any LazySequenceProtocol\<UInt32\>, I put any LazySequenceProtocol & Sequence\<UInt32\>. To my surprise, the compiler complained: error: non-pro…

---

## [Idea: Testing Set Inclusion](https://forums.swift.org/t/idea-testing-set-inclusion/73613)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 0\
**Last updated:** [August 1, 2024, 3:09am UTC](https://forums.swift.org/t/idea-testing-set-inclusion/73613 "2024-08-01T03:09:39Z")

</div>

I made a new implementation of testing if one sorted sequence is contained within another. (The tested elements need not be contiguous in the receiver.) It's an analog of the C++ std::includes function. The current cod…

---

## [Are primary associated types supposed to be transitive?](https://forums.swift.org/t/are-primary-associated-types-supposed-to-be-transitive/72985)

<div class="topic-metadata">

**Author:** [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Replies:** 2\
**Last updated:** [July 6, 2024, 6:33pm UTC](https://forums.swift.org/t/are-primary-associated-types-supposed-to-be-transitive/72985 "2024-07-06T18:33:39Z")

</div>

Have a function that returns "some Sequence\<MyElement\>." The sequence type is also a lazy sequence, but "some LazySequenceProtocol\<MyElement\>" doesn't work. So: Transitivity is supposed to work, but there's a (major) …

---

## [How unique/useful is this twist on contains(), is there a better way to do this?](https://forums.swift.org/t/how-unique-useful-is-this-twist-on-contains-is-there-a-better-way-to-do-this/71127)

<div class="topic-metadata">

**Author:** [@jpmhouston](https://forums.swift.org/u/jpmhouston)\
**Replies:** 7\
**Last updated:** [April 10, 2024, 12:21am UTC](https://forums.swift.org/t/how-unique-useful-is-this-twist-on-contains-is-there-a-better-way-to-do-this/71127 "2024-04-10T00:21:05Z")

</div>

I defined an onlyIfNotIn function for this one use case I had where I wanted to use contains() more naturally and in a chained expression: let foos = things.compactMap({ $0.foo?.onlyIfNotIn(\[a,b,c\]) }) And then went ah…

---

## [There's no ends(with:) counterpart to starts(with:)](https://forums.swift.org/t/theres-no-ends-with-counterpart-to-starts-with/70121)

<div class="topic-metadata">

**Author:** [@AlexanderM](https://forums.swift.org/u/AlexanderM)\
**Replies:** 2\
**Last updated:** [February 28, 2024, 4:03pm UTC](https://forums.swift.org/t/theres-no-ends-with-counterpart-to-starts-with/70121 "2024-02-28T16:03:18Z")

</div>

So I made one: Add \`ends(with:)\` by amomchilov · Pull Request #224 · apple/swift-algorithms · GitHub. Would love some feedback! For comparison, there's Sequence.starts(with:). This seems like an odd omission from the s…

---

## [\[Pitch\] Sequence grouped(by:) and keyed(by:)](https://forums.swift.org/t/pitch-sequence-grouped-by-and-keyed-by/65511)

<div class="topic-metadata">

**Author:** [@AlexanderM](https://forums.swift.org/u/AlexanderM)\
**Replies:** 20\
**Last updated:** [December 5, 2023, 10:09pm UTC](https://forums.swift.org/t/pitch-sequence-grouped-by-and-keyed-by/65511 "2023-12-05T22:09:12Z")

</div>

Hey Swift Community! I propose adding new APIs to simplfy the process of building dictionaries from Sequences: let digitsGroupedByMod3 = (0...9).grouped(by: { $0 % 3 }) // Results in: \[ 0: \[0, 3, 6, 9\], 1: \[1, 4, 7\],…

---

## [Compiler optimisations for functional-style Collection algorithms](https://forums.swift.org/t/compiler-optimisations-for-functional-style-collection-algorithms/68291)

<div class="topic-metadata">

**Author:** [@wadetregaskis](https://forums.swift.org/u/wadetregaskis)\
**Replies:** 20\
**Last updated:** [November 14, 2023, 7:39pm UTC](https://forums.swift.org/t/compiler-optimisations-for-functional-style-collection-algorithms/68291 "2023-11-14T19:39:13Z")

</div>

I'm exploring Swift's performance in some basic situations involving operations on Collections and Sequences. As part of that, I've been benchmarking the difference between programming styles (using simple, contrived al…

---

## [Difference in behavior between \`first\` and \`first(where: { \_ in true })\` used on lazy sequence](https://forums.swift.org/t/difference-in-behavior-between-first-and-first-where-in-true-used-on-lazy-sequence/63770)

<div class="topic-metadata">

**Author:** [@KoCMoHaBTa](https://forums.swift.org/u/KoCMoHaBTa)\
**Replies:** 1\
**Last updated:** [March 17, 2023, 2:13pm UTC](https://forums.swift.org/t/difference-in-behavior-between-first-and-first-where-in-true-used-on-lazy-sequence/63770 "2023-03-17T14:13:19Z")

</div>

Hi, I would like to ask, why there is a difference in the behavior of using first vs first(where: { \_ in true }) on lazy sequence. I was expecting both to be the same. Is this a bug or expected. If expected - why? Her…
