Skip to content

Commit

Permalink
feat: rename to _rangeIterable, localDateRangeIterable
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Jan 2, 2024
1 parent 52d6c61 commit fe25e8f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/array/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export function _range(fromIncl: number, toExcl?: number, step = 1): number[] {
/**
* Like _range, but returns an Iterable2.
*/
export function _rangeIt(toExcl: number): Iterable2<number>
export function _rangeIt(fromIncl: number, toExcl: number, step?: number): Iterable2<number>
export function _rangeIt(fromIncl: number, toExcl?: number, step = 1): Iterable2<number> {
export function _rangeIterable(toExcl: number): Iterable2<number>
export function _rangeIterable(fromIncl: number, toExcl: number, step?: number): Iterable2<number>
export function _rangeIterable(fromIncl: number, toExcl?: number, step = 1): Iterable2<number> {
if (toExcl === undefined) {
toExcl = fromIncl
fromIncl = 0
Expand Down
4 changes: 2 additions & 2 deletions src/datetime/localDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
localDateOrToday,
localDateOrUndefined,
localDateRange,
localDateRangeIt,
localDateRangeIterable,
localDateToday,
} from './localDate'

Expand Down Expand Up @@ -248,7 +248,7 @@ test('range', () => {
})

test('rangeIterable', () => {
expect([...localDateRangeIt('2021-12-24', '2021-12-26')]).toMatchInlineSnapshot(`
expect([...localDateRangeIterable('2021-12-24', '2021-12-26')]).toMatchInlineSnapshot(`
[
"2021-12-24",
"2021-12-25",
Expand Down
4 changes: 2 additions & 2 deletions src/datetime/localDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,13 @@ export function localDateRange(
step = 1,
stepUnit: LocalDateUnit = 'day',
): LocalDate[] {
return localDateRangeIt(min, max, incl, step, stepUnit).toArray()
return localDateRangeIterable(min, max, incl, step, stepUnit).toArray()
}

/**
* Experimental, returns the range as Iterable2.
*/
export function localDateRangeIt(
export function localDateRangeIterable(
min: LocalDateInput,
max: LocalDateInput,
incl: Inclusiveness = '[)',
Expand Down
20 changes: 10 additions & 10 deletions src/iter/iterable2.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { _rangeIt } from '../array/range'
import { _rangeIterable } from '../array/range'
import { Iterable2 } from './iterable2'

test('iterable2', () => {
expect(_rangeIt(3).toArray()).toEqual([0, 1, 2])
expect(_rangeIterable(3).toArray()).toEqual([0, 1, 2])

expect(_rangeIt(1, 4).find(v => v % 2 === 0)).toBe(2)
expect(_rangeIt(1, 4).some(v => v % 2 === 0)).toBe(true)
expect(_rangeIt(1, 4).some(v => v % 2 === -1)).toBe(false)
expect(_rangeIt(1, 4).every(v => v % 2 === 0)).toBe(false)
expect(_rangeIt(1, 4).every(v => v > 0)).toBe(true)
expect(_rangeIterable(1, 4).find(v => v % 2 === 0)).toBe(2)
expect(_rangeIterable(1, 4).some(v => v % 2 === 0)).toBe(true)
expect(_rangeIterable(1, 4).some(v => v % 2 === -1)).toBe(false)
expect(_rangeIterable(1, 4).every(v => v % 2 === 0)).toBe(false)
expect(_rangeIterable(1, 4).every(v => v > 0)).toBe(true)

expect(
_rangeIt(1, 4)
_rangeIterable(1, 4)
.filter(v => v % 2 === 1)
.toArray(),
).toEqual([1, 3])

expect(
_rangeIt(1, 4)
_rangeIterable(1, 4)
.map(v => v * 2)
.toArray(),
).toEqual([2, 4, 6])

const a: number[] = []
_rangeIt(1, 4).forEach(v => a.push(v))
_rangeIterable(1, 4).forEach(v => a.push(v))
expect(a).toEqual([1, 2, 3])

expect(Iterable2.of([]).toArray()).toEqual([])
Expand Down

0 comments on commit fe25e8f

Please sign in to comment.