| 1 |
#Region "Microsoft.VisualBasic::b61fb90525a79191455dc08f6f84ebf6, Microsoft.VisualBasic.Core\Extensions\Collection\Linq\NumericSequence.vb"
|
| 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 |
#End Region
|
| 42 |
|
| 43 |
Imports System.Runtime.CompilerServices
|
| 44 |
Imports Microsoft.VisualBasic.Language
|
| 45 |
Imports Microsoft.VisualBasic.Language.Default
|
| 46 |
|
| 47 |
Namespace Linq
|
| 48 |
|
| 49 |
Public Module NumericSequence
|
| 50 |
|
| 51 |
<Extension>
|
| 52 |
Public Function InRange(Of T As IComparable)(x As T, min As T, max As T) As Boolean
|
| 53 |
If x.LessThanOrEquals(max) AndAlso x.GreaterThanOrEquals(min) Then
|
| 54 |
Return True
|
| 55 |
Else
|
| 56 |
Return False
|
| 57 |
End If
|
| 58 |
End Function
|
| 59 |
|
| 60 |
Public Iterator Function Range(from%, to%, Optional step% = 1) As IEnumerable(Of Integer)
|
| 61 |
For i As Integer = from To [to] Step [step]
|
| 62 |
Yield i
|
| 63 |
Next
|
| 64 |
End Function
|
| 65 |
|
| 66 |
Public Iterator Function Range(from#, to#, Optional step# = 1) As IEnumerable(Of Double)
|
| 67 |
For i As Double = from To [to] Step [step]
|
| 68 |
Yield i
|
| 69 |
Next
|
| 70 |
End Function
|
| 71 |
|
| 72 |
Public Iterator Function Range(from!, to!, Optional step! = 1) As IEnumerable(Of Single)
|
| 73 |
For i As Single = from To [to] Step [step]
|
| 74 |
Yield i
|
| 75 |
Next
|
| 76 |
End Function
|
| 77 |
|
| 78 |
Public Iterator Function Range(from&, to&, Optional step& = 1) As IEnumerable(Of Long)
|
| 79 |
For i As Long = from To [to] Step [step]
|
| 80 |
Yield i
|
| 81 |
Next
|
| 82 |
End Function
|
| 83 |
|
| 84 |
Public Iterator Function Range(from@, to@, Optional step@ = 1) As IEnumerable(Of Decimal)
|
| 85 |
For i As Decimal = from To [to] Step [step]
|
| 86 |
Yield i
|
| 87 |
Next
|
| 88 |
End Function
|
| 89 |
|
| 90 |
Public Iterator Function Range(from As Short, [to] As Short, Optional [step] As Short = 1) As IEnumerable(Of Short)
|
| 91 |
For i As Short = from To [to] Step [step]
|
| 92 |
Yield i
|
| 93 |
Next
|
| 94 |
End Function
|
| 95 |
|
| 96 |
Public ReadOnly OneDay As DefaultValue(Of TimeSpan) = New TimeSpan(days:=1, hours:=0, minutes:=0, seconds:=0)
|
| 97 |
Public ReadOnly OneHour As DefaultValue(Of TimeSpan) = New TimeSpan(hours:=1, minutes:=0, seconds:=0)
|
| 98 |
Public ReadOnly OneMinute As DefaultValue(Of TimeSpan) = New TimeSpan(minutes:=1, seconds:=0, hours:=0)
|
| 99 |
Public ReadOnly OneSecond As DefaultValue(Of TimeSpan) = New TimeSpan(seconds:=1, hours:=0, minutes:=0)
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
</summary>
|
| 104 |
<param name="from"></param>
|
| 105 |
<param name="[to]"></param>
|
| 106 |
<param name="step%">Milliseconds</param>
|
| 107 |
<returns></returns>
|
| 108 |
Public Iterator Function Range(from As Date, [to] As Date, Optional [step] As TimeSpan = Nothing) As IEnumerable(Of Date)
|
| 109 |
Dim t As TimeSpan = [step] Or OneDay
|
| 110 |
|
| 111 |
|
| 112 |
Yield from
|
| 113 |
|
| 114 |
If from < [to] Then
|
| 115 |
Do While from < [to]
|
| 116 |
from = from + t
|
| 117 |
Yield from
|
| 118 |
Loop
|
| 119 |
Else
|
| 120 |
Do While from > [to]
|
| 121 |
from = from - t
|
| 122 |
Yield from
|
| 123 |
Loop
|
| 124 |
End If
|
| 125 |
End Function
|
| 126 |
End Module
|
| 127 |
End Namespace
|