Skip to content

Commit

Permalink
Simplified map2
Browse files Browse the repository at this point in the history
- removing the check of both types
  • Loading branch information
manofstick committed Oct 14, 2016
1 parent 5bc1981 commit ceaed6c
Showing 1 changed file with 4 additions and 30 deletions.
34 changes: 4 additions & 30 deletions src/fsharp/FSharp.Core/seq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,9 @@ namespace Microsoft.FSharp.Collections
inherit SeqComponentFactory<'T,'U> ()
override __.Create<'V> (_result:Result<'V>) (next:SeqComponent<'U,'V>) : SeqComponent<'T,'V> = next.CreateMap map

and Map2FirstFactory<'First,'Second,'U> (map:'First->'Second->'U, input2:IEnumerable<'Second>) =
and Map2Factory<'First,'Second,'U> (map:'First->'Second->'U, input2:IEnumerable<'Second>) =
inherit SeqComponentFactory<'First,'U> ()
override __.Create<'V> (result:Result<'V>) (next:SeqComponent<'U,'V>) : SeqComponent<'First,'V> = upcast Map2First (map, input2, result, next)

and Map2SecondFactory<'First,'Second,'U> (map:'First->'Second->'U, input1:IEnumerable<'First>) =
inherit SeqComponentFactory<'Second,'U> ()
override __.Create<'V> (result:Result<'V>) (next:SeqComponent<'U,'V>) : SeqComponent<'Second,'V> = upcast Map2Second (map, input1, result, next)
override __.Create<'V> (result:Result<'V>) (next:SeqComponent<'U,'V>) : SeqComponent<'First,'V> = upcast Map2 (map, input2, result, next)

and Map3Factory<'First,'Second,'Third,'U> (map:'First->'Second->'Third->'U, input2:IEnumerable<'Second>, input3:IEnumerable<'Third>) =
inherit SeqComponentFactory<'First,'U> ()
Expand Down Expand Up @@ -731,7 +727,7 @@ namespace Microsoft.FSharp.Collections
override __.ProcessNext (input:'T) : bool =
Helpers.avoidTailCall (next.ProcessNext (map input))

and Map2First<'First,'Second,'U,'V> (map:'First->'Second->'U, enumerable2:IEnumerable<'Second>, result:Result<'V>, next:SeqComponent<'U,'V>) =
and Map2<'First,'Second,'U,'V> (map:'First->'Second->'U, enumerable2:IEnumerable<'Second>, result:Result<'V>, next:SeqComponent<'U,'V>) =
inherit SeqComponent<'First,'V>(next)

let input2 = enumerable2.GetEnumerator ()
Expand All @@ -751,26 +747,6 @@ namespace Microsoft.FSharp.Collections
finally
(Helpers.upcastISeqComponent next).OnDispose ()

and Map2Second<'First,'Second,'U,'V> (map:'First->'Second->'U, enumerable1:IEnumerable<'First>, result:Result<'V>, next:SeqComponent<'U,'V>) =
inherit SeqComponent<'Second,'V>(next)

let input1 = enumerable1.GetEnumerator ()
let map' = OptimizedClosures.FSharpFunc<_,_,_>.Adapt map

override __.ProcessNext (input:'Second) : bool =
if input1.MoveNext () then
Helpers.avoidTailCall (next.ProcessNext (map'.Invoke (input1.Current, input)))
else
result.StopFurtherProcessing ()
false

interface ISeqComponent with
override __.OnDispose () =
try
input1.Dispose ()
finally
(Helpers.upcastISeqComponent next).OnDispose ()

and Map3<'First,'Second,'Third,'U,'V> (map:'First->'Second->'Third->'U, enumerable2:IEnumerable<'Second>, enumerable3:IEnumerable<'Third>, result:Result<'V>, next:SeqComponent<'U,'V>) =
inherit SeqComponent<'First,'V>(next)

Expand Down Expand Up @@ -1513,9 +1489,7 @@ namespace Microsoft.FSharp.Collections
let map2<'T,'U,'V> (f:'T->'U->'V) (source1:seq<'T>) (source2:seq<'U>) : seq<'V> =
checkNonNull "source1" source1
checkNonNull "source2" source2
match source1 with
| :? SeqComposer.Enumerable.EnumerableBase<'T> as s -> s.Compose (SeqComposer.Map2FirstFactory (f, source2))
| _ -> source2 |> seqFactory (SeqComposer.Map2SecondFactory (f, source1))
source1 |> seqFactory (SeqComposer.Map2Factory (f, source2))

[<CompiledName("Map3")>]
let map3 f source1 source2 source3 =
Expand Down

0 comments on commit ceaed6c

Please sign in to comment.