Skip to content

Commit ceaed6c

Browse files
committed
Simplified map2
- removing the check of both types
1 parent 5bc1981 commit ceaed6c

File tree

1 file changed

+4
-30
lines changed

1 file changed

+4
-30
lines changed

Diff for: src/fsharp/FSharp.Core/seq.fs

+4-30
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,9 @@ namespace Microsoft.FSharp.Collections
599599
inherit SeqComponentFactory<'T,'U> ()
600600
override __.Create<'V> (_result:Result<'V>) (next:SeqComponent<'U,'V>) : SeqComponent<'T,'V> = next.CreateMap map
601601

602-
and Map2FirstFactory<'First,'Second,'U> (map:'First->'Second->'U, input2:IEnumerable<'Second>) =
602+
and Map2Factory<'First,'Second,'U> (map:'First->'Second->'U, input2:IEnumerable<'Second>) =
603603
inherit SeqComponentFactory<'First,'U> ()
604-
override __.Create<'V> (result:Result<'V>) (next:SeqComponent<'U,'V>) : SeqComponent<'First,'V> = upcast Map2First (map, input2, result, next)
605-
606-
and Map2SecondFactory<'First,'Second,'U> (map:'First->'Second->'U, input1:IEnumerable<'First>) =
607-
inherit SeqComponentFactory<'Second,'U> ()
608-
override __.Create<'V> (result:Result<'V>) (next:SeqComponent<'U,'V>) : SeqComponent<'Second,'V> = upcast Map2Second (map, input1, result, next)
604+
override __.Create<'V> (result:Result<'V>) (next:SeqComponent<'U,'V>) : SeqComponent<'First,'V> = upcast Map2 (map, input2, result, next)
609605

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

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

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

754-
and Map2Second<'First,'Second,'U,'V> (map:'First->'Second->'U, enumerable1:IEnumerable<'First>, result:Result<'V>, next:SeqComponent<'U,'V>) =
755-
inherit SeqComponent<'Second,'V>(next)
756-
757-
let input1 = enumerable1.GetEnumerator ()
758-
let map' = OptimizedClosures.FSharpFunc<_,_,_>.Adapt map
759-
760-
override __.ProcessNext (input:'Second) : bool =
761-
if input1.MoveNext () then
762-
Helpers.avoidTailCall (next.ProcessNext (map'.Invoke (input1.Current, input)))
763-
else
764-
result.StopFurtherProcessing ()
765-
false
766-
767-
interface ISeqComponent with
768-
override __.OnDispose () =
769-
try
770-
input1.Dispose ()
771-
finally
772-
(Helpers.upcastISeqComponent next).OnDispose ()
773-
774750
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>) =
775751
inherit SeqComponent<'First,'V>(next)
776752

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

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

0 commit comments

Comments
 (0)