Skip to content

Commit

Permalink
Fix issue in Value|Option.Sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
fcallejon committed Nov 18, 2023
1 parent 299a3a1 commit 7f970a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/FSharpPlus/Control/Traversable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ type Sequence =

[<EditorBrowsable(EditorBrowsableState.Never)>]
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
Expand Down
14 changes: 8 additions & 6 deletions src/FSharpPlus/Extensions/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,17 @@ 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

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
Expand All @@ -169,16 +170,17 @@ 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

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
Expand Down

0 comments on commit 7f970a6

Please sign in to comment.