-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSequence.Generators.cs
82 lines (74 loc) · 3.1 KB
/
Sequence.Generators.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
namespace ABCNET.Utils
{
/// <summary>
/// Ïðåäîñòàâëÿåò ôóíêöèîíàë äëÿ ðàáîòû ñ ïîñëåäîâàòåëüíîñòÿìè.
/// </summary>
public static partial class Sequence
{
#region public
/// <summary>
/// Ñîçäà¸ò ïîñëåäîâàòåëüíîñòü íà îñíîâå ôóíêöèè ñåëåêòîðà.
/// </summary>
/// <param name="count">Êîëè÷åñòâî ýëåìåíòîâ.</param>
/// <param name="selector">Ôóíêöèÿ ñåëåêòîð.</param>
/// <param name="firstIndex">Íà÷àëüíûé èíäåêñ.</param>
/// <returns>Ïîñëåäîâàòåëüíîñòü.</returns>
public static IEnumerable<T> By<T>(int count, Func<int, T> selector, int firstIndex = 0)
{
if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count));
if (selector == null)
throw new ArgumentNullException(nameof(selector));
for (int i = 0; i < count; i++)
yield return selector(i + firstIndex);
}
/// <summary>
/// Ñîçäà¸ò ïîñëåäîâàòåëüíîñòü ñëó÷àéíûõ ÷èñåë òèïà Integer.
/// </summary>
/// <param name="count">Êîëè÷åñòâî ýëåìåíòîâ.</param>
/// <param name="low">Íèæíÿÿ ãðàíèöà äèàïàçîíà.</param>
/// <param name="high">Âåðõíÿÿ ãðàíèöà äèàïàçîíà.</param>
/// <returns>Ïîñëåäîâàòåëüíîñòü.</returns>
public static IEnumerable<int> Random(int count, int low = Int32BordersHelper.Low, int high = Int32BordersHelper.High)
{
if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count));
if (low > high)
throw new ArgumentException(nameof(low));
for (int i = 0; i < count; i++)
yield return Base.Random(low, high);
}
/// <summary>
/// Ñîçäà¸ò ïîñëåäîâàòåëüíîñòü ñëó÷àéíûõ ÷èñåë òèïà Real.
/// </summary>
/// <param name="count">Êîëè÷åñòâî ýëåìåíòîâ.</param>
/// <param name="low">Íèæíÿÿ ãðàíèöà äèàïàçîíà.</param>
/// <param name="high">Âåðõíÿÿ ãðàíèöà äèàïàçîíà.</param>
/// <returns>Ïîñëåäîâàòåëüíîñòü.</returns>
public static IEnumerable<double> Random(int count, double low = DoubleBordersHelper.Low, double high = DoubleBordersHelper.High)
{
if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count));
if (low > high)
throw new ArgumentException(nameof(low));
for (int i = 0; i < count; i++)
yield return Base.Random(low, high);
}
/// <summary>
/// Ñîçäà¸ò ïîñëåäîâàòåëüíîñòü, çàïîëíåííóþ óêàçàííûì çíà÷åíèåì.
/// </summary>
/// <param name="count">Êîëè÷åñòâî ýëåìåíòîâ.</param>
/// <param name="value">Çíà÷åíèå.</param>
/// <returns>Ïîñëåäîâàòåëüíîñòü.</returns>
public static IEnumerable<T> Fill<T>(int count, T value)
{
if (count < 0)
throw new ArgumentOutOfRangeException(nameof(count));
for (int i = 0; i < count; i++)
yield return value;
}
#endregion public
}
}