-
-
Notifications
You must be signed in to change notification settings - Fork 127
/
repeat.ts
57 lines (55 loc) · 1.4 KB
/
repeat.ts
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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
/**
* Create an iterator which repeats a value a number of times.
*
* @deprecated
*
* @param value - The value to repeat.
*
* @param count - The number of times to repeat the value.
*
* @returns A new iterator which repeats the specified value.
*
* #### Example
* ```typescript
* import { repeat } from '@lumino/algorithm';
*
* let stream = repeat(7, 3);
*
* Array.from(stream); // [7, 7, 7]
* ```
*/
export function* repeat<T>(value: T, count: number): IterableIterator<T> {
while (0 < count--) {
yield value;
}
}
/**
* Create an iterator which yields a value a single time.
*
* @deprecated
*
* @param value - The value to wrap in an iterator.
*
* @returns A new iterator which yields the value a single time.
*
* #### Example
* ```typescript
* import { once } from '@lumino/algorithm';
*
* let stream = once(7);
*
* Array.from(stream); // [7]
* ```
*/
export function* once<T>(value: T): IterableIterator<T> {
yield value;
}