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 b0b70a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ We should add as much concrete implementations for primitive types (types coming

#### Defaults

The goal of default implementations is to allow users of the library to write less code, as an example we expect the user will add `Bind` , `Return` to their specific monad types, but we don't want to force them to add `Join` although if they do, code might be more efficient.
The goal of default implementations is to allow users of the library to write less code, as an example we expect the user will add `Bind` , `Return` to their specific monad types, but we don't want to force him to add `Join` although if he adds it, code might be more efficient.
But those defaults are not intended to be used by developers of F#+ as we should afford writing more code in order to maximize usability of the library. You can read this as "the principle is to allow user to write less boilerplate, and because of that we have to put some boilerplate inside F#+".

#### Invoker
Expand Down
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 b0b70a8

Please sign in to comment.