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

Commit e3d4efe

Browse files
committed
Implement Enumerable.Repeat
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.
1 parent 1d57d54 commit e3d4efe

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

JSIL.Libraries/Includes/Bootstrap/Linq/Classes/System.Linq.Enumerable.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,32 @@
557557
}
558558
);
559559

560+
$.Method({ Static: true, Public: true }, "Repeat",
561+
new JSIL.MethodSignature(
562+
$jsilcore.TypeRef("System.Collections.Generic.IEnumerable`1", ["!!0"]),
563+
["!!0", "System.Int32"],
564+
["TResult"]),
565+
function Repeat$b1(TResult, element, count) {
566+
var i = 0;
567+
568+
return new (JSIL.AbstractEnumerable.Of(TResult))(
569+
function getNext(result) {
570+
if (i < count) {
571+
i++;
572+
result.set(element);
573+
return true;
574+
}
575+
return false;
576+
},
577+
function reset() {
578+
i = 0;
579+
},
580+
function dispose() {
581+
}
582+
);
583+
}
584+
);
585+
560586
$.Method({ Static: true, Public: true }, "Where",
561587
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"]),
562588
function Where$b1(TSource, source, predicate) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
public static class Program {
7+
public static void Main () {
8+
9+
foreach (var x in Enumerable.Repeat("x", 5))
10+
Console.WriteLine(x);
11+
12+
}
13+
}

Tests/SimpleTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@
311311
<None Include="SimpleTestCases\EnumInPlaceAdd.cs" />
312312
<None Include="SimpleTestCases\EnumerableStringMethod.cs" />
313313
<None Include="SimpleTestCases\EnumerableSkip.cs" />
314+
<None Include="SimpleTestCases\EnumerableRepeat.cs" />
314315
<None Include="SimpleTestCases\UnboxBoolean.cs" />
315316
<None Include="SimpleTestCases\MathIntrinsics.cs" />
316317
<None Include="SimpleTestCases\StringSplitDefaultSeparators.cs" />

0 commit comments

Comments
 (0)