Fsharp.Core :: {Array;List;Set;Array.Parallel} partitionWith (taking Choice<T,U> partitioner)#19335
Open
Fsharp.Core :: {Array;List;Set;Array.Parallel} partitionWith (taking Choice<T,U> partitioner)#19335
Conversation
Adds List.partitionWith that splits a list into two lists of potentially different types using a Choice-returning partitioner function. - Implementation in list.fs using ListCollector and recursive loop - Signature with XML docs and example in list.fsi - Unit tests covering basic, empty, all-Choice1, all-Choice2, single element, and order preservation cases
Adds Array.partitionWith function that splits an array into two arrays by applying a partitioner function returning Choice<'T1,'T2>. Uses ArrayCollector<'T> for efficient array building. Includes XML documentation with example and unit tests covering: - Basic type-changing partition - Empty array input - All Choice1Of2 / all Choice2Of2 - Single element - Order preservation - Null input throws ArgumentNullException
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- List: stack safety test with 100k elements verifying tail recursion - List/Array/Set: exception propagation tests with InvalidOperationException Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tests Replace Assert.Throws<InvalidOperationException> with the existing CheckThrowsInvalidOperationExn helper from LibraryTestFx.fs for consistency with the rest of the test codebase. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds FsCheck property-based consistency tests to CollectionModulesConsistency.fs: - List vs Array: verifies identical ordered results across int, string, NormalFloat - Set vs Array: verifies set-equal results (order-independent) across int, string, NormalFloat Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace iter-based ascending traversal with right→key→left recursive traversal, matching partitionAux's proven strategy. Elements are inserted largest-first into output trees, causing fewer rebalancing rotations. Internal accumulator uses struct tuples to avoid per-step allocations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace ChunkedArrayCollector with a two-pass strategy: - Pass 1: call partitioner, store results, count Choice1Of2 - Pass 2: allocate exact-sized arrays, scatter results Mark function inline with [<InlineIfLambda>] on partitioner parameter. Remove ChunkedArrayCollector type (only used by partitionWith). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rewrite body to use ListCollector instead of freshConsNoTail/setFreshConsTail to avoid FieldAccessException when inlined into external assemblies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Implement the parallel version of Array.partitionWith using the same Parallel.For + thread-local accumulator + Interlocked.Add pattern as Array.Parallel.choose. - Implementation in src/FSharp.Core/array.fs - Signature with XML docs in src/FSharp.Core/array.fsi - Unit tests and consistency tests - Surface area baselines updated (4 .bsl files) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ase notes - Replace intermediate Choice<'T1,'T2>[] in Array.partitionWith with the 3-array pattern (bool[] + T1[] + T2[]) matching the parallel version, eliminating N per-element heap allocations of Choice DU objects - Add Array.Parallel.partitionWith to release notes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
❗ Release notes required
Warning No PR link found in some release notes, please consider adding it.
|
Member
|
No Choice<'a, 'b, 'c> or Choice<'a, 'b, 'c, 'd> versions? |
Member
Author
fsharp/fslang-suggestions#1119 (comment) But your question made me realize that if we wanted to support all various sorts (all the 7 choices, and result,..), it could be solved by a language-level facility that inverts collection of N-case DU items, and puts them into N different collections of respective fields of those cases. Maybe more on the "type provider generate types+members from existing types" side ... ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements fsharp/fslang-suggestions#1119
Signatures
Example — active patterns
A total active pattern
(|A|B|)is already'T -> Choice<'T1, 'T2>— pass it directly.