From 7f970a662d642a7d55369d2ee37854236f01736c Mon Sep 17 00:00:00 2001 From: Fernando Callejon Date: Sat, 18 Nov 2023 19:42:55 +0000 Subject: [PATCH] Fix issue in Value|Option.Sequence --- src/FSharpPlus/Control/Traversable.fs | 16 ++++++++-------- src/FSharpPlus/Extensions/Extensions.fs | 14 ++++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/FSharpPlus/Control/Traversable.fs b/src/FSharpPlus/Control/Traversable.fs index 7c33a2e00..347501c7b 100644 --- a/src/FSharpPlus/Control/Traversable.fs +++ b/src/FSharpPlus/Control/Traversable.fs @@ -17,14 +17,14 @@ type Sequence = [] static member inline ForInfiniteSequences (t: seq<_>, isFailure, conversion) = - let add x y = y :: x - let mutable go = true - let mutable r = result [] - use e = t.GetEnumerator () - while go && e.MoveNext () do - if isFailure e.Current then go <- false - r <- Map.Invoke add r <*> e.Current - Map.Invoke (List.rev >> conversion) r + let add x y = y :: x + let mutable go = true + let mutable r = result [] + use e = t.GetEnumerator () + while go && e.MoveNext () do + if isFailure e.Current then go <- false + r <- Map.Invoke add r <*> e.Current + Map.Invoke (List.rev >> conversion) r type Traverse = inherit Default1 diff --git a/src/FSharpPlus/Extensions/Extensions.fs b/src/FSharpPlus/Extensions/Extensions.fs index 851fa0ae0..016c17b19 100644 --- a/src/FSharpPlus/Extensions/Extensions.fs +++ b/src/FSharpPlus/Extensions/Extensions.fs @@ -140,7 +140,7 @@ module Extensions = let mutable accumulator = ArrayCollector<'t> () let mutable noneFound = false use e = t.GetEnumerator () - while e.MoveNext () && noneFound do + while e.MoveNext () && not noneFound do match e.Current with | Some v -> accumulator.Add v | None -> noneFound <- true @@ -148,8 +148,9 @@ module Extensions = if noneFound then None else - let res = accumulator.Close () - if res.Length = 0 then None else Array.toSeq res |> Some + accumulator.Close () + |> Array.toSeq + |> Some #endif type ValueOption<'t> with @@ -169,7 +170,7 @@ module Extensions = let mutable accumulator = ArrayCollector<'t> () let mutable noneFound = false use e = t.GetEnumerator () - while e.MoveNext () && noneFound do + while e.MoveNext () && not noneFound do match e.Current with | ValueSome v -> accumulator.Add v | ValueNone -> noneFound <- true @@ -177,8 +178,9 @@ module Extensions = if noneFound then ValueNone else - let res = accumulator.Close () - if res.Length = 0 then ValueNone else Array.toSeq res |> ValueSome + accumulator.Close () + |> Array.toSeq + |> ValueSome #endif type Choice<'t, 'error> with