From ade94114810dbe78e2a9f96e2d1f059a6f4c38a0 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 30 Jul 2025 15:09:05 +0000
Subject: [PATCH 1/6] Initial plan
From 5ee70f4c69adbcca87b33c534e52cd056b56ce9b Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 30 Jul 2025 15:27:02 +0000
Subject: [PATCH 2/6] Add complexity documentation to first 5 Seq functions
(allPairs, append, average, averageBy, cache, cast, choose)
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
---
src/FSharp.Core/seq.fsi | 41 +++++++++++++++++++++++++++++++++++------
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/src/FSharp.Core/seq.fsi b/src/FSharp.Core/seq.fsi
index 24189d3730c..cc0d57a007b 100644
--- a/src/FSharp.Core/seq.fsi
+++ b/src/FSharp.Core/seq.fsi
@@ -21,6 +21,11 @@ module Seq =
///
/// Thrown when either of the input sequences is null.
///
+ ///
+ /// Time Complexity: O(n * m) - where n is the length of source1 and m is the length of source2
+ /// Space Complexity: O(m) - for caching source2, plus O(1) for lazy evaluation
+ ///
+ ///
///
///
/// ([1; 2], [3; 4]) ||> Seq.allPairs
@@ -38,7 +43,11 @@ module Seq =
///
/// The returned sequence may be passed between threads safely. However,
/// individual IEnumerator values generated from the returned sequence should not be accessed
- /// concurrently.
+ /// concurrently.
+ ///
+ /// Time Complexity: O(1) - for lazy sequence construction, O(n + m) for full enumeration
+ /// Space Complexity: O(1) - lazy evaluation with constant overhead
+ ///
///
/// The first sequence.
/// The second sequence.
@@ -60,7 +69,11 @@ module Seq =
/// Returns the average of the elements in the sequence.
///
/// The elements are averaged using the + operator, DivideByInt method and Zero property
- /// associated with the element type.
+ /// associated with the element type.
+ ///
+ /// Time Complexity: O(n) - where n is the length of the source sequence
+ /// Space Complexity: O(1) - constant space for accumulating sum and count
+ ///
///
/// The input sequence.
///
@@ -93,7 +106,11 @@ module Seq =
/// of the sequence.
///
/// The elements are averaged using the + operator, DivideByInt method and Zero property
- /// associated with the generated type.
+ /// associated with the generated type.
+ ///
+ /// Time Complexity: O(n) - where n is the length of the source sequence
+ /// Space Complexity: O(1) - constant space for accumulating sum and count
+ ///
///
/// A function applied to transform each element of the sequence.
/// The input sequence.
@@ -151,7 +168,11 @@ module Seq =
/// The enumerator may be disposed and underlying cache storage released by
/// converting the returned sequence object to type IDisposable, and calling the Dispose method
/// on this object. The sequence object may then be re-enumerated and a fresh enumerator will
- /// be used.
+ /// be used.
+ ///
+ /// Time Complexity: O(1) - for initial setup, O(k) for accessing k elements from cache
+ /// Space Complexity: O(k) - where k is the number of elements accessed from the source sequence
+ ///
///
/// The input sequence.
///
@@ -177,7 +198,11 @@ module Seq =
/// The use of this function usually requires a type annotation.
/// An incorrect type annotation may result in runtime type
/// errors.
- /// Individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
+ /// Individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
+ ///
+ /// Time Complexity: O(1) - for lazy sequence construction, O(n) for full enumeration
+ /// Space Complexity: O(1) - lazy evaluation with constant overhead
+ ///
///
/// The input sequence.
///
@@ -200,7 +225,11 @@ module Seq =
///
/// The returned sequence may be passed between threads safely. However,
/// individual IEnumerator values generated from the returned sequence should not
- /// be accessed concurrently.
+ /// be accessed concurrently.
+ ///
+ /// Time Complexity: O(1) - for lazy sequence construction, O(n) for full enumeration
+ /// Space Complexity: O(1) - lazy evaluation with constant overhead
+ ///
///
/// A function to transform items of type T into options of type U.
/// The input sequence of type T.
From 3aabd6ebbc18cf4375de5cb3d6528be809ebcff7 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 30 Jul 2025 15:30:27 +0000
Subject: [PATCH 3/6] Add complexity documentation to 5 more Seq functions
(chunkBySize, collect, compareWith, concat, contains)
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
---
src/FSharp.Core/seq.fsi | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/FSharp.Core/seq.fsi b/src/FSharp.Core/seq.fsi
index cc0d57a007b..125e7f916e6 100644
--- a/src/FSharp.Core/seq.fsi
+++ b/src/FSharp.Core/seq.fsi
@@ -264,6 +264,11 @@ module Seq =
/// Thrown when the input sequence is null.
/// Thrown when chunkSize is not positive.
///
+ ///
+ /// Time Complexity: O(1) - for lazy sequence construction, O(n) for full enumeration
+ /// Space Complexity: O(chunkSize) - for each chunk array, plus O(1) for lazy evaluation
+ ///
+ ///
///
///
/// [1; 2; 3] |> Seq.chunkBySize 2
@@ -283,7 +288,11 @@ module Seq =
/// Applies the given function to each element of the sequence and concatenates all the
/// results.
///
- /// Remember sequence is lazy, effects are delayed until it is enumerated.
+ /// Remember sequence is lazy, effects are delayed until it is enumerated.
+ ///
+ /// Time Complexity: O(1) - for lazy sequence construction, O(n + Σk_i) for full enumeration where k_i is the length of each mapped subsequence
+ /// Space Complexity: O(1) - lazy evaluation with constant overhead
+ ///
///
/// A function to transform elements of the input sequence into the sequences
/// that will then be concatenated.
@@ -329,6 +338,11 @@ module Seq =
/// Thrown when either of the input sequences
/// is null.
///
+ ///
+ /// Time Complexity: O(min(n, m)) - where n and m are lengths of the sequences, stops at first difference
+ /// Space Complexity: O(1) - constant space for comparison
+ ///
+ ///
///
///
/// let closerToNextDozen a b =
@@ -400,7 +414,11 @@ module Seq =
/// enumeration.
///
/// The returned sequence may be passed between threads safely. However,
- /// individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
+ /// individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
+ ///
+ /// Time Complexity: O(1) - for lazy sequence construction, O(Σn_i) for full enumeration where n_i is the length of each subsequence
+ /// Space Complexity: O(1) - lazy evaluation with constant overhead
+ ///
///
/// The input enumeration-of-enumerations.
///
@@ -428,6 +446,11 @@ module Seq =
///
/// Thrown when the input sequence is null.
///
+ ///
+ /// Time Complexity: O(n) - where n is the position of the element or the length of the sequence if not found
+ /// Space Complexity: O(1) - constant space for comparison
+ ///
+ ///
///
///
/// [1; 2] |> Seq.contains 2 // evaluates to true
From 92365eebbef8ec247df2e316c053c4574ab2fa94 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 30 Jul 2025 15:34:45 +0000
Subject: [PATCH 4/6] Add complexity documentation to 6 more Seq functions
(countBy, delay, distinct, distinctBy, splitInto, empty, except)
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
---
src/FSharp.Core/seq.fsi | 39 +++++++++++++++++++++++++++++++++++----
1 file changed, 35 insertions(+), 4 deletions(-)
diff --git a/src/FSharp.Core/seq.fsi b/src/FSharp.Core/seq.fsi
index 125e7f916e6..4a2d1ce9254 100644
--- a/src/FSharp.Core/seq.fsi
+++ b/src/FSharp.Core/seq.fsi
@@ -466,7 +466,11 @@ module Seq =
/// Note that this function returns a sequence that digests the whole initial sequence as soon as
/// that sequence is iterated. As a result this function should not be used with
/// large or infinite sequences. The function makes no assumption on the ordering of the original
- /// sequence.
+ /// sequence.
+ ///
+ /// Time Complexity: O(n) - where n is the length of the source sequence
+ /// Space Complexity: O(k) - where k is the number of unique keys
+ ///
///
/// A function transforming each item of the input sequence into a key to be
/// compared against the others.
@@ -493,7 +497,11 @@ module Seq =
/// sequence.
///
/// The input function is evaluated each time an IEnumerator for the sequence
- /// is requested.
+ /// is requested.
+ ///
+ /// Time Complexity: O(1) - for creating the delayed sequence wrapper
+ /// Space Complexity: O(1) - constant overhead for the delay mechanism
+ ///
///
/// The generating function for the sequence.
/// The result sequence.
@@ -518,6 +526,11 @@ module Seq =
///
/// Thrown when the input sequence is null.
///
+ ///
+ /// Time Complexity: O(n) - where n is the length of the source sequence
+ /// Space Complexity: O(k) - where k is the number of distinct elements
+ ///
+ ///
///
///
/// [1; 1; 2; 3] |> Seq.distinct
@@ -538,6 +551,11 @@ module Seq =
///
/// Thrown when the input sequence is null.
///
+ ///
+ /// Time Complexity: O(n) - where n is the length of the source sequence
+ /// Space Complexity: O(k) - where k is the number of distinct keys
+ ///
+ ///
///
///
/// let inputs = [{Bar = 1 };{Bar = 1}; {Bar = 2}; {Bar = 3}]
@@ -552,7 +570,11 @@ module Seq =
/// Splits the input sequence into at most count chunks.
///
/// This function returns a sequence that digests the whole initial sequence as soon as that
- /// sequence is iterated. As a result this function should not be used with large or infinite sequences.
+ /// sequence is iterated. As a result this function should not be used with large or infinite sequences.
+ ///
+ /// Time Complexity: O(n) - where n is the length of the source sequence
+ /// Space Complexity: O(n) - for materializing the sequence and creating chunks
+ ///
///
/// The maximum number of chunks.
/// The input sequence.
@@ -588,6 +610,11 @@ module Seq =
///
/// An empty sequence.
///
+ ///
+ /// Time Complexity: O(1) - constant time creation
+ /// Space Complexity: O(1) - no memory allocation for empty sequence
+ ///
+ ///
///
///
/// Seq.empty // Evaluates to seq { }
@@ -603,7 +630,11 @@ module Seq =
/// Note that this function returns a sequence that digests the whole of the first input sequence as soon as
/// the result sequence is iterated. As a result this function should not be used with
/// large or infinite sequences in the first parameter. The function makes no assumption on the ordering of the first input
- /// sequence.
+ /// sequence.
+ ///
+ /// Time Complexity: O(n + m) - where n is the length of itemsToExclude and m is the length of source
+ /// Space Complexity: O(n) - for storing the exclusion set from itemsToExclude
+ ///
///
/// A sequence whose elements that also occur in the second sequence will cause those elements to be
/// removed from the returned sequence.
From 9b16616c7e61d6486bc7f32a9fdae214d2fc144a Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 30 Jul 2025 15:37:59 +0000
Subject: [PATCH 5/6] Add complexity documentation to 5 more critical Seq
functions (exists, exists2, filter, where, find)
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
---
src/FSharp.Core/seq.fsi | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/FSharp.Core/seq.fsi b/src/FSharp.Core/seq.fsi
index 4a2d1ce9254..02d4052bb31 100644
--- a/src/FSharp.Core/seq.fsi
+++ b/src/FSharp.Core/seq.fsi
@@ -660,7 +660,11 @@ module Seq =
///
/// The predicate is applied to the elements of the input sequence. If any application
/// returns true then the overall result is true and no further elements are tested.
- /// Otherwise, false is returned.
+ /// Otherwise, false is returned.
+ ///
+ /// Time Complexity: O(n) - where n is the position of the first matching element, or length of sequence if none match
+ /// Space Complexity: O(1) - constant space for evaluation
+ ///
///
/// A function to test each item of the input sequence.
/// The input sequence.
@@ -694,7 +698,11 @@ module Seq =
/// The predicate is applied to matching elements in the two sequences up to the lesser of the
/// two lengths of the collections. If any application returns true then the overall result is
/// true and no further elements are tested. Otherwise, false is returned. If one sequence is shorter than
- /// the other then the remaining elements of the longer sequence are ignored.
+ /// the other then the remaining elements of the longer sequence are ignored.
+ ///
+ /// Time Complexity: O(min(n, m)) - where n and m are the lengths of the sequences, stops at first match
+ /// Space Complexity: O(1) - constant space for evaluation
+ ///
///
/// A function to test each pair of items from the input sequences.
/// The first input sequence.
@@ -732,7 +740,11 @@ module Seq =
/// The returned sequence may be passed between threads safely. However,
/// individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
///
- /// Remember sequence is lazy, effects are delayed until it is enumerated.
+ /// Remember sequence is lazy, effects are delayed until it is enumerated.
+ ///
+ /// Time Complexity: O(1) - for lazy sequence construction, O(n) for full enumeration where n is the source length
+ /// Space Complexity: O(1) - lazy evaluation with constant overhead
+ ///
///
/// A function to test whether each item in the input sequence should be included in the output.
/// The input sequence.
@@ -760,7 +772,11 @@ module Seq =
///
/// Remember sequence is lazy, effects are delayed until it is enumerated.
///
- /// A synonym for Seq.filter.
+ /// A synonym for Seq.filter.
+ ///
+ /// Time Complexity: O(1) - for lazy sequence construction, O(n) for full enumeration where n is the source length
+ /// Space Complexity: O(1) - lazy evaluation with constant overhead
+ ///
///
/// A function to test whether each item in the input sequence should be included in the output.
/// The input sequence.
@@ -789,6 +805,11 @@ module Seq =
/// evaluated by the predicate
/// Thrown when the input sequence is null
///
+ ///
+ /// Time Complexity: O(n) - where n is the position of the first matching element, or length of sequence if none match
+ /// Space Complexity: O(1) - constant space for evaluation
+ ///
+ ///
///
///
/// let inputs = [1; 2; 3]
From fe01fa0d9e96e80dafeaa0f6804e8066287b84eb Mon Sep 17 00:00:00 2001
From: GH Actions
Date: Thu, 31 Jul 2025 08:48:46 +0000
Subject: [PATCH 6/6] Apply patch from /run fantomas
---
src/FSharp.Core/seq.fsi | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/FSharp.Core/seq.fsi b/src/FSharp.Core/seq.fsi
index 02d4052bb31..948c539bb0a 100644
--- a/src/FSharp.Core/seq.fsi
+++ b/src/FSharp.Core/seq.fsi
@@ -527,7 +527,7 @@ module Seq =
/// Thrown when the input sequence is null.
///
///
- /// Time Complexity: O(n) - where n is the length of the source sequence
+ /// Time Complexity: O(n) - where n is the length of the source sequence
/// Space Complexity: O(k) - where k is the number of distinct elements
///
///