Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Implement Enumerable.Repeat
Browse files Browse the repository at this point in the history
The external method Repeat<TResult>(TResult,int) was not implemented.
This commit introduces a test case and matching implementation returning
a JSIL AbstractEnumerable returning the element the appropriate number
of times.
  • Loading branch information
mwh committed Feb 28, 2018
1 parent 1d57d54 commit e3d4efe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,32 @@
}
);

$.Method({ Static: true, Public: true }, "Repeat",
new JSIL.MethodSignature(
$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", ["!!0"]),
["!!0", "System.Int32"],
["TResult"]),
function Repeat$b1(TResult, element, count) {
var i = 0;

return new (JSIL.AbstractEnumerable.Of(TResult))(
function getNext(result) {
if (i < count) {
i++;
result.set(element);
return true;
}
return false;
},
function reset() {
i = 0;
},
function dispose() {
}
);
}
);

$.Method({ Static: true, Public: true }, "Where",
new JSIL.MethodSignature($jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", ["!!0"]), [$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", ["!!0"]), $jsilcore.TypeRef("System.Func`2", ["!!0", $.Boolean])], ["TSource"]),
function Where$b1(TSource, source, predicate) {
Expand Down
13 changes: 13 additions & 0 deletions Tests/SimpleTestCases/EnumerableRepeat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public static class Program {
public static void Main () {

foreach (var x in Enumerable.Repeat("x", 5))
Console.WriteLine(x);

}
}
1 change: 1 addition & 0 deletions Tests/SimpleTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
<None Include="SimpleTestCases\EnumInPlaceAdd.cs" />
<None Include="SimpleTestCases\EnumerableStringMethod.cs" />
<None Include="SimpleTestCases\EnumerableSkip.cs" />
<None Include="SimpleTestCases\EnumerableRepeat.cs" />
<None Include="SimpleTestCases\UnboxBoolean.cs" />
<None Include="SimpleTestCases\MathIntrinsics.cs" />
<None Include="SimpleTestCases\StringSplitDefaultSeparators.cs" />
Expand Down

0 comments on commit e3d4efe

Please sign in to comment.