semantic-typescript 0.0.7 โ 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/readme.cn.md +441 -247
- package/readme.de.md +434 -240
- package/readme.es.md +434 -240
- package/readme.fr.md +434 -240
- package/readme.jp.md +434 -240
- package/readme.kr.md +441 -247
- package/readme.md +434 -240
- package/readme.ru.md +529 -0
- package/readme.tw.md +441 -247
package/readme.kr.md
CHANGED
|
@@ -1,335 +1,529 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Semantic-TypeScript ์คํธ๋ฆผ ์ฒ๋ฆฌ ํ๋ ์์ํฌ
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
์ปฌ๋ ์
, ์คํธ๋ฆผ, ์ํ์ค๋ฅผ ํจ์ํ ์คํ์ผ๋ก ๋ค๋ฃฐ ์ ์๋ ๊ตฌ์ฑ ์์๋ค์ ์ ๊ณตํ๋ฉฐ, ์ ๋ ฌ, ํํฐ๋ง, ๊ทธ๋ฃนํ, ํต๊ณ ๋ถ์ ๋ฑ์ ์ง์ํฉ๋๋ค.
|
|
3
|
+
## ์๊ฐ
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
Semantic-TypeScript๋ JavaScript GeneratorFunction, Java Stream ๋ฐ MySQL Index์์ ์๊ฐ์ ๋ฐ์ ํ๋์ ์ธ ์คํธ๋ฆผ ์ฒ๋ฆฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์
๋๋ค. ํต์ฌ ์ค๊ณ ์ฒ ํ์ ๋ฐ์ดํฐ ์ธ๋ฑ์ฑ์ ํตํด ํจ์จ์ ์ธ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ํ์ดํ๋ผ์ธ์ ๊ตฌ์ถํ๋ ๋ฐ ์์ผ๋ฉฐ, ํ๋ก ํธ์๋ ๊ฐ๋ฐ์ ์ํด ํ์
์์ ์ ์ด๊ณ ํจ์ํ ์คํ์ผ์ ์คํธ๋ฆฌ๋ฐ ์์
๊ฒฝํ์ ์ ๊ณตํฉ๋๋ค.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
๊ธฐ์กด์ ๋๊ธฐ์ ์ฒ๋ฆฌ์ ๋ฌ๋ฆฌ Semantic์ ๋น๋๊ธฐ ์ฒ๋ฆฌ ๋ชจ๋ธ์ ์ฑํํฉ๋๋ค. ๋ฐ์ดํฐ ์คํธ๋ฆผ์ ์์ฑํ ๋ ์ต์ข
๋ฐ์ดํฐ ์์ ์์ ์ ์ ์ ์ผ๋ก ์
์คํธ๋ฆผ์ด `accept` ๋ฐ `interrupt` ์ฝ๋ฐฑ ํจ์๋ฅผ ํธ์ถํ๋ ์์ ์ ๋ฐ๋ผ ๊ฒฐ์ ๋ฉ๋๋ค. ์ด ์ค๊ณ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ค์๊ฐ ๋ฐ์ดํฐ ์คํธ๋ฆผ, ๋์ฉ๋ ๋ฐ์ดํฐ ์ธํธ ๋ฐ ๋น๋๊ธฐ ๋ฐ์ดํฐ ์์ค๋ฅผ ์ฐ์ํ๊ฒ ์ฒ๋ฆฌํ ์ ์๊ฒ ํฉ๋๋ค.
|
|
9
8
|
|
|
10
|
-
##
|
|
9
|
+
## ํต์ฌ ๊ธฐ๋ฅ
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
11
|
+
| ๊ธฐ๋ฅ | ์ค๋ช
| ์ฅ์ |
|
|
12
|
+
|------|------|------|
|
|
13
|
+
| **ํ์
์์ ์ ๋ค๋ฆญ** | ์์ ํ TypeScript ํ์
์ง์ | ์ปดํ์ผ ํ์ ์ค๋ฅ ๊ฐ์ง, ๋ ๋์ ๊ฐ๋ฐ ๊ฒฝํ |
|
|
14
|
+
| **ํจ์ํ ํ๋ก๊ทธ๋๋ฐ** | ๋ถ๋ณ ๋ฐ์ดํฐ ๊ตฌ์กฐ ๋ฐ ์์ ํจ์ | ์์ธก ๊ฐ๋ฅํ ์ฝ๋, ์ฌ์ด ํ
์คํธ ๋ฐ ์ ์ง๋ณด์ |
|
|
15
|
+
| **์ง์ฐ ํ๊ฐ** | ์ฃผ๋ฌธํ ๊ณ์ฐ, ์ฑ๋ฅ ์ต์ ํ | ๋์ฉ๋ ๋ฐ์ดํฐ ์ฒ๋ฆฌ ์ ๋์ ๋ฉ๋ชจ๋ฆฌ ํจ์จ |
|
|
16
|
+
| **๋น๋๊ธฐ ์คํธ๋ฆผ ์ฒ๋ฆฌ** | ์ ๋๋ ์ดํฐ ๊ธฐ๋ฐ ๋น๋๊ธฐ ๋ฐ์ดํฐ ์คํธ๋ฆผ | ์ค์๊ฐ ๋ฐ์ดํฐ ๋ฐ ์ด๋ฒคํธ ๊ธฐ๋ฐ ์๋๋ฆฌ์ค์ ์ ํฉ |
|
|
17
|
+
| **๋ค์ค ํจ๋ฌ๋ค์ ์์ง๊ธฐ** | ์ ๋ ฌ, ๋น์ ๋ ฌ, ํต๊ณ์ ์์ง ์ ๋ต | ๋ค์ํ ์๋๋ฆฌ์ค์ ๋ฐ๋ฅธ ์ต์ ์ ๋ต ์ ํ |
|
|
18
|
+
| **ํต๊ณ ๋ถ์** | ๋ด์ฅ๋ ์์ ํ ํต๊ณ ๊ณ์ฐ ํจ์ | ํตํฉ ๋ฐ์ดํฐ ๋ถ์ ๋ฐ ๋ณด๊ณ ์ ์์ฑ |
|
|
19
|
+
|
|
20
|
+
## ์ฑ๋ฅ ๊ณ ๋ ค ์ฌํญ
|
|
21
|
+
|
|
22
|
+
**์ค์ ์ฐธ๊ณ **: ๋ค์ ๋ฉ์๋๋ค์ ๋ฐ์ดํฐ๋ฅผ ์์งํ๊ณ ์ ๋ ฌํ๊ธฐ ์ํด ์ฑ๋ฅ์ ํฌ์ํฉ๋๋ค:
|
|
23
|
+
- `toOrdered()`
|
|
24
|
+
- `toWindow()`
|
|
25
|
+
- `toNumericStatistics()`
|
|
26
|
+
- `toBigIntStatistics()`
|
|
27
|
+
- `sorted()`
|
|
28
|
+
- `sorted(comparator)`
|
|
29
|
+
|
|
30
|
+
ํนํ ์ค์: `sorted()` ๋ฐ `sorted(comparator)`๋ ๋ค์ ๋ฉ์๋๋ค์ ๊ฒฐ๊ณผ๋ฅผ ์ฌ์ ์ํฉ๋๋ค:
|
|
31
|
+
- `redirect(redirector)`
|
|
32
|
+
- `translate(translator)`
|
|
33
|
+
- `shuffle(mapper)`
|
|
34
|
+
|
|
35
|
+
## ํฉํ ๋ฆฌ ๋ฉ์๋
|
|
36
|
+
|
|
37
|
+
### ์คํธ๋ฆผ ์์ฑ ํฉํ ๋ฆฌ
|
|
38
|
+
|
|
39
|
+
| ๋ฉ์๋ | ์๊ทธ๋์ฒ | ์ค๋ช
| ์์ |
|
|
40
|
+
|------|------|------|------|
|
|
41
|
+
| `blob` | `(blob: Blob, chunk?: bigint) => Semantic<Uint8Array>` | Blob์ ๋ฐ์ดํธ ์คํธ๋ฆผ์ผ๋ก ๋ณํ | `blob(fileBlob, 1024n)` |
|
|
42
|
+
| `empty` | `<E>() => Semantic<E>` | ๋น ์คํธ๋ฆผ ์์ฑ | `empty<number>()` |
|
|
43
|
+
| `fill` | `<E>(element: E, count: bigint) => Semantic<E>` | ์ง์ ๋ ์์ ์์๋ก ์ฑ์ | `fill("hello", 5n)` |
|
|
44
|
+
| `from` | `<E>(iterable: Iterable<E>) => Semantic<E>` | ๋ฐ๋ณต ๊ฐ๋ฅ ๊ฐ์ฒด๋ก๋ถํฐ ์คํธ๋ฆผ ์์ฑ | `from([1, 2, 3])` |
|
|
45
|
+
| `range` | `<N extends number\|bigint>(start: N, end: N, step?: N) => Semantic<N>` | ์ซ์ ๋ฒ์ ์คํธ๋ฆผ ์์ฑ | `range(1, 10, 2)` |
|
|
46
|
+
| `iterate` | `<E>(generator: Generator<E>) => Semantic<E>` | ์ ๋๋ ์ดํฐ ํจ์๋ก๋ถํฐ ์คํธ๋ฆผ ์์ฑ | `iterate(myGenerator)` |
|
|
47
|
+
| `websocket` | `(websocket: WebSocket) => Semantic<MessageEvent>` | WebSocket์ผ๋ก๋ถํฐ ์ด๋ฒคํธ ์คํธ๋ฆผ ์์ฑ | `websocket(socket)` |
|
|
48
|
+
|
|
49
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
50
|
+
```typescript
|
|
51
|
+
import { from, range, fill, empty } from 'semantic-typescript';
|
|
31
52
|
|
|
32
|
-
|
|
53
|
+
// ๋ฐฐ์ด๋ก๋ถํฐ ์คํธ๋ฆผ ์์ฑ
|
|
54
|
+
const numberStream = from([1, 2, 3, 4, 5]);
|
|
33
55
|
|
|
34
|
-
|
|
56
|
+
// ์ซ์ ๋ฒ์ ์คํธ๋ฆผ ์์ฑ
|
|
57
|
+
const rangeStream = range(1, 10, 2); // 1, 3, 5, 7, 9
|
|
35
58
|
|
|
36
|
-
|
|
59
|
+
// ๋ฐ๋ณต ์์๋ก ์ฑ์
|
|
60
|
+
const filledStream = fill("hello", 3n); // "hello", "hello", "hello"
|
|
37
61
|
|
|
38
|
-
|
|
62
|
+
// ๋น ์คํธ๋ฆผ ์์ฑ
|
|
63
|
+
const emptyStream = empty<number>();
|
|
64
|
+
```
|
|
39
65
|
|
|
40
|
-
|
|
41
|
-
|--------|------|------|
|
|
42
|
-
| `of(value)` | ๊ฐ ๊ฐ์ธ๊ธฐ (null ๊ฐ๋ฅ) | `Optional.of(null)` |
|
|
43
|
-
| `ofNullable(v)` | null ํ์ฉํ์ฌ ๊ฐ์ธ๊ธฐ | `Optional.ofNullable(someVar)` |
|
|
44
|
-
| `ofNonNull(v)` | null์ด๋ฉด ์์ธ ๋ฐ์ | `Optional.ofNonNull(5)` |
|
|
45
|
-
| `get()` | ๊ฐ ๊ฐ์ ธ์ค๊ธฐ (์์ผ๋ฉด ์์ธ) | `opt.get()` |
|
|
46
|
-
| `getOrDefault(d)` | ๊ฐ ๊ฐ์ ธ์ค๊ธฐ ๋๋ ๊ธฐ๋ณธ๊ฐ | `opt.getOrDefault(0)` |
|
|
47
|
-
| `ifPresent(fn)` | ๊ฐ์ด ์์ผ๋ฉด ๋ถ์์ฉ ์คํ | `opt.ifPresent(x => console.log(x))` |
|
|
48
|
-
| `map(fn)` | ๊ฐ์ด ์์ผ๋ฉด ๋ณํ | `opt.map(x => x + 1)` |
|
|
49
|
-
| `filter(fn)` | ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๊ฐ๋ง ์ ์ง | `opt.filter(x => x > 0)` |
|
|
50
|
-
| `isEmpty()` | ๋น์ด์๋์ง ํ์ธ | `opt.isEmpty()` |
|
|
51
|
-
| `isPresent()` | ๊ฐ์ด ์๋์ง ํ์ธ | `opt.isPresent()` |
|
|
66
|
+
### ์ ํธ๋ฆฌํฐ ํจ์ ํฉํ ๋ฆฌ
|
|
52
67
|
|
|
53
|
-
|
|
68
|
+
| ๋ฉ์๋ | ์๊ทธ๋์ฒ | ์ค๋ช
| ์์ |
|
|
69
|
+
|------|------|------|------|
|
|
70
|
+
| `validate` | `<T>(t: MaybeInvalid<T>) => t is T` | ๊ฐ์ด ์ ํจํ์ง ๊ฒ์ฆ | `validate(null)` โ `false` |
|
|
71
|
+
| `invalidate` | `<T>(t: MaybeInvalid<T>) => t is null\|undefined` | ๊ฐ์ด ๋ฌดํจํ์ง ๊ฒ์ฆ | `invalidate(0)` โ `false` |
|
|
72
|
+
| `useCompare` | `<T>(t1: T, t2: T) => number` | ์ผ๋ฐ ๋น๊ต ํจ์ | `useCompare("a", "b")` โ `-1` |
|
|
73
|
+
| `useRandom` | `<T = number\|bigint>(index: T) => T` | ์์ฌ ๋์ ์์ฑ๊ธฐ | `useRandom(5)` โ ๋์ |
|
|
54
74
|
|
|
75
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
55
76
|
```typescript
|
|
56
|
-
import {
|
|
77
|
+
import { validate, invalidate, useCompare, useRandom } from 'semantic-typescript';
|
|
57
78
|
|
|
58
|
-
|
|
79
|
+
// ๋ฐ์ดํฐ ์ ํจ์ฑ ๊ฒ์ฆ
|
|
80
|
+
const data: string | null = "hello";
|
|
81
|
+
if (validate(data)) {
|
|
82
|
+
console.log(data.toUpperCase()); // validate๊ฐ ๋ฐ์ดํฐ๊ฐ null์ด ์๋์ ๋ณด์ฅํ๋ฏ๋ก ์์ ํ ํธ์ถ
|
|
83
|
+
}
|
|
59
84
|
|
|
60
|
-
const
|
|
85
|
+
const nullData: string | null = null;
|
|
86
|
+
if (invalidate(nullData)) {
|
|
87
|
+
console.log("๋ฐ์ดํฐ ๋ฌดํจ"); // invalidate๊ฐ null์ ๊ฐ์งํ์ผ๋ฏ๋ก ์คํ๋จ
|
|
88
|
+
}
|
|
61
89
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
.map(v => v * 2)
|
|
65
|
-
.getOrDefault(0);
|
|
90
|
+
// ๊ฐ ๋น๊ต
|
|
91
|
+
const comparison = useCompare("apple", "banana"); // -1
|
|
66
92
|
|
|
67
|
-
|
|
93
|
+
// ๋์ ์์ฑ
|
|
94
|
+
const randomNum = useRandom(42); // ์๋ 42 ๊ธฐ๋ฐ ๋์
|
|
68
95
|
```
|
|
69
96
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
### 2. `Semantic<E>` โ ์ง์ฐ ํ๊ฐ ๋ฐ์ดํฐ ์คํธ๋ฆผ
|
|
97
|
+
## ํต์ฌ ํด๋์ค ์์ธ
|
|
73
98
|
|
|
74
|
-
|
|
99
|
+
### Optional<T> - ์์ ํ Null ๊ฐ ์ฒ๋ฆฌ
|
|
75
100
|
|
|
76
|
-
|
|
101
|
+
Optional ํด๋์ค๋ null ๋๋ undefined์ผ ์ ์๋ ๊ฐ์ ์์ ํ๊ฒ ์ฒ๋ฆฌํ๊ธฐ ์ํ ํจ์ํ ์ ๊ทผ ๋ฐฉ์์ ์ ๊ณตํฉ๋๋ค.
|
|
77
102
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
|
81
|
-
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
84
|
-
| `
|
|
85
|
-
| `
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
|
90
|
-
|--------|------|------|
|
|
91
|
-
| `map(fn)` | ๊ฐ ์์ ๋ณํ | `.map(x => x * 2)` |
|
|
92
|
-
| `filter(fn)` | ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์์๋ง ์ ์ง | `.filter(x => x > 10)` |
|
|
93
|
-
| `limit(n)` | ์ฒ์ N๊ฐ ์์๋ก ์ ํ | `.limit(5)` |
|
|
94
|
-
| `skip(n)` | ์ฒ์ N๊ฐ ์์ ๊ฑด๋๋ฐ๊ธฐ | `.skip(2)` |
|
|
95
|
-
| `distinct()` | ์ค๋ณต ์ ๊ฑฐ (๊ธฐ๋ณธ์ ์ผ๋ก Set ์ฌ์ฉ) | `.distinct()` |
|
|
96
|
-
| `sorted()` | ์์ ์ ๋ ฌ (์์ฐ ์์) | `.sorted()` |
|
|
97
|
-
| `sorted(comparator)` | ์ปค์คํ
์ ๋ ฌ | `.sorted((a, b) => a - b)` |
|
|
98
|
-
| `toOrdered()` | ์ ๋ ฌ ํ `OrderedCollectable` ๋ฐํ | `.toOrdered()` |
|
|
99
|
-
| `toUnordered()` | **์ ๋ ฌ ์์ โ ๊ฐ์ฅ ๋น ๋ฆ** | `.toUnordered()` โ
|
|
|
100
|
-
| `collect(collector)` | ์ปฌ๋ ํฐ๋ก ์ง๊ณ | `.collect(Collector.full(...))` |
|
|
101
|
-
| `toArray()` | ๋ฐฐ์ด๋ก ๋ณํ | `.toArray()` |
|
|
102
|
-
| `toSet()` | Set์ผ๋ก ๋ณํ | `.toSet()` |
|
|
103
|
-
| `toMap(keyFn, valFn)` | Map์ผ๋ก ๋ณํ | `.toMap(x => x.id, x => x)` |
|
|
104
|
-
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
### 3. `toUnordered()` โ ๐ ๊ฐ์ฅ ๋น ๋ฆ, ์ ๋ ฌ ์์
|
|
108
|
-
|
|
109
|
-
**์ ๋ ฌ์ด ํ์ ์๊ณ ์ต๊ณ ์ ์ฑ๋ฅ์ ์ํ๋ค๋ฉด** ์๋์ ๊ฐ์ด ์ฌ์ฉํ์ธ์:
|
|
103
|
+
| ๋ฉ์๋ | ๋ฐํ ํ์
| ์ค๋ช
| ์๊ฐ ๋ณต์ก๋ |
|
|
104
|
+
|------|----------|------|------------|
|
|
105
|
+
| `filter(predicate: Predicate<T>)` | `Optional<T>` | ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๊ฐ ํํฐ๋ง | O(1) |
|
|
106
|
+
| `get()` | `T` | ๊ฐ ๊ฐ์ ธ์ค๊ธฐ, ๋น์ด์์ผ๋ฉด ์ค๋ฅ ๋ฐ์ | O(1) |
|
|
107
|
+
| `getOrDefault(defaultValue: T)` | `T` | ๊ฐ ๋๋ ๊ธฐ๋ณธ๊ฐ ๊ฐ์ ธ์ค๊ธฐ | O(1) |
|
|
108
|
+
| `ifPresent(action: Consumer<T>)` | `void` | ๊ฐ์ด ์กด์ฌํ๋ฉด ์ก์
์คํ | O(1) |
|
|
109
|
+
| `isEmpty()` | `boolean` | ๋น์ด์๋์ง ํ์ธ | O(1) |
|
|
110
|
+
| `isPresent()` | `boolean` | ๊ฐ์ด ์กด์ฌํ๋์ง ํ์ธ | O(1) |
|
|
111
|
+
| `map<R>(mapper: Functional<T, R>)` | `Optional<R>` | ๊ฐ ๋งคํ ๋ฐ ๋ณํ | O(1) |
|
|
112
|
+
| `static of<T>(value: MaybeInvalid<T>)` | `Optional<T>` | Optional ์ธ์คํด์ค ์์ฑ | O(1) |
|
|
113
|
+
| `static ofNullable<T>(value?)` | `Optional<T>` | nullable Optional ์์ฑ | O(1) |
|
|
114
|
+
| `static ofNonNull<T>(value: T)` | `Optional<T>` | non-null Optional ์์ฑ | O(1) |
|
|
110
115
|
|
|
116
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
111
117
|
```typescript
|
|
112
|
-
|
|
113
|
-
```
|
|
118
|
+
import { Optional } from 'semantic-typescript';
|
|
114
119
|
|
|
115
|
-
|
|
116
|
-
|
|
120
|
+
// Optional ์ธ์คํด์ค ์์ฑ
|
|
121
|
+
const optionalValue = Optional.ofNullable<string>(Math.random() > 0.5 ? "hello" : null);
|
|
117
122
|
|
|
118
|
-
|
|
123
|
+
// ์ฐ์ ์ฐ์ฐ
|
|
124
|
+
const result = optionalValue
|
|
125
|
+
.filter(val => val.length > 3) // ๊ธธ์ด๊ฐ 3๋ณด๋ค ํฐ ๊ฐ ํํฐ๋ง
|
|
126
|
+
.map(val => val.toUpperCase()) // ๋๋ฌธ์๋ก ๋ณํ
|
|
127
|
+
.getOrDefault("default"); // ๊ฐ ๋๋ ๊ธฐ๋ณธ๊ฐ ๊ฐ์ ธ์ค๊ธฐ
|
|
119
128
|
|
|
120
|
-
|
|
129
|
+
console.log(result); // "HELLO" ๋๋ "default"
|
|
121
130
|
|
|
122
|
-
|
|
131
|
+
// ์์ ํ ์ฐ์ฐ
|
|
132
|
+
optionalValue.ifPresent(val => {
|
|
133
|
+
console.log(`๊ฐ ์กด์ฌ: ${val}`);
|
|
134
|
+
});
|
|
123
135
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
136
|
+
// ์ํ ํ์ธ
|
|
137
|
+
if (optionalValue.isPresent()) {
|
|
138
|
+
console.log("๊ฐ ์์");
|
|
139
|
+
} else if (optionalValue.isEmpty()) {
|
|
140
|
+
console.log("๋น์ด ์์");
|
|
141
|
+
}
|
|
128
142
|
```
|
|
129
143
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
144
|
+
### Semantic<E> - ์ง์ฐ ๋ฐ์ดํฐ ์คํธ๋ฆผ
|
|
145
|
+
|
|
146
|
+
Semantic์ ํ๋ถํ ์คํธ๋ฆผ ์ฐ์ฐ์๋ฅผ ์ ๊ณตํ๋ ํต์ฌ ์คํธ๋ฆผ ์ฒ๋ฆฌ ํด๋์ค์
๋๋ค.
|
|
147
|
+
|
|
148
|
+
#### ์คํธ๋ฆผ ๋ณํ ์ฐ์ฐ
|
|
149
|
+
|
|
150
|
+
| ๋ฉ์๋ | ๋ฐํ ํ์
| ์ค๋ช
| ์ฑ๋ฅ ์ํฅ |
|
|
151
|
+
|------|----------|------|----------|
|
|
152
|
+
| `concat(other: Semantic<E>)` | `Semantic<E>` | ๋ ์คํธ๋ฆผ ์ฐ๊ฒฐ | O(n+m) |
|
|
153
|
+
| `distinct()` | `Semantic<E>` | ์ค๋ณต ์ ๊ฑฐ (Set ์ฌ์ฉ) | O(n) |
|
|
154
|
+
| `distinct(comparator)` | `Semantic<E>` | ์ฌ์ฉ์ ์ ์ ๋น๊ต์ ์ค๋ณต ์ ๊ฑฐ | O(nยฒ) |
|
|
155
|
+
| `dropWhile(predicate)` | `Semantic<E>` | ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์์ ์์ ๋ฒ๋ฆผ | O(n) |
|
|
156
|
+
| `filter(predicate)` | `Semantic<E>` | ์์ ํํฐ๋ง | O(n) |
|
|
157
|
+
| `flat(mapper)` | `Semantic<E>` | ์ค์ฒฉ ์คํธ๋ฆผ ํํํ | O(nรm) |
|
|
158
|
+
| `flatMap(mapper)` | `Semantic<R>` | ๋งคํ ๋ฐ ํํํ | O(nรm) |
|
|
159
|
+
| `limit(n)` | `Semantic<E>` | ์์ ์ ์ ํ | O(n) |
|
|
160
|
+
| `map(mapper)` | `Semantic<R>` | ์์ ๋งคํ ๋ฐ ๋ณํ | O(n) |
|
|
161
|
+
| `peek(consumer)` | `Semantic<E>` | ์์ ํ์ธ (์์ ์์) | O(n) |
|
|
162
|
+
| `redirect(redirector)` | `Semantic<E>` | ์ธ๋ฑ์ค ์ฌ์ง์ | O(n) |
|
|
163
|
+
| `reverse()` | `Semantic<E>` | ์คํธ๋ฆผ ์์ ๋ฐ์ | O(n) |
|
|
164
|
+
| `shuffle()` | `Semantic<E>` | ๋ฌด์์ ์
ํ | O(n) |
|
|
165
|
+
| `shuffle(mapper)` | `Semantic<E>` | ์ฌ์ฉ์ ์ ์ ์
ํ ๋ก์ง | O(n) |
|
|
166
|
+
| `skip(n)` | `Semantic<E>` | ์ฒ์ n๊ฐ ์์ ๊ฑด๋๋ | O(n) |
|
|
167
|
+
| `sub(start, end)` | `Semantic<E>` | ๋ถ๋ถ ์คํธ๋ฆผ ๊ฐ์ ธ์ค๊ธฐ | O(n) |
|
|
168
|
+
| `takeWhile(predicate)` | `Semantic<E>` | ์กฐ๊ฑด์ ๋ง์กฑํ๋ ์์ ์์ ๊ฐ์ ธ์ค๊ธฐ | O(n) |
|
|
169
|
+
| `translate(offset)` | `Semantic<E>` | ์ธ๋ฑ์ค ๋ณํ | O(n) |
|
|
170
|
+
| `translate(translator)` | `Semantic<E>` | ์ฌ์ฉ์ ์ ์ ์ธ๋ฑ์ค ๋ณํ | O(n) |
|
|
171
|
+
|
|
172
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
173
|
+
```typescript
|
|
174
|
+
import { from } from 'semantic-typescript';
|
|
135
175
|
|
|
136
|
-
|
|
176
|
+
const stream = from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
137
177
|
|
|
138
|
-
|
|
178
|
+
// ์คํธ๋ฆผ ๋ณํ ์ฐ์ฐ ์์
|
|
179
|
+
const processedStream = stream
|
|
180
|
+
.filter(x => x % 2 === 0) // ์ง์ ํํฐ๋ง
|
|
181
|
+
.map(x => x * 2) // ๊ฐ ์์์ 2 ๊ณฑํ๊ธฐ
|
|
182
|
+
.distinct() // ์ค๋ณต ์ ๊ฑฐ
|
|
183
|
+
.limit(3) // ์ฒ์ 3๊ฐ ์์๋ก ์ ํ
|
|
184
|
+
.peek((val, index) => console.log(`์ธ๋ฑ์ค ${index}์ ์์ ${val}`)); // ์์ ํ์ธ
|
|
139
185
|
|
|
140
|
-
|
|
141
|
-
Collector.full(identity, accumulator, finisher)
|
|
142
|
-
Collector.shortable(identity, interruptor, accumulator, finisher)
|
|
186
|
+
// ์ฐธ๊ณ : ์คํธ๋ฆผ์ ์์ง ์คํ๋์ง ์์, ํฐ๋ฏธ๋ ์ฐ์ฐ์ ์ํด Collectable๋ก ๋ณํ ํ์
|
|
143
187
|
```
|
|
144
188
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
---
|
|
189
|
+
#### ์คํธ๋ฆผ ํฐ๋ฏธ๋ ์ฐ์ฐ
|
|
148
190
|
|
|
149
|
-
|
|
191
|
+
| ๋ฉ์๋ | ๋ฐํ ํ์
| ์ค๋ช
| ์ฑ๋ฅ ํน์ฑ |
|
|
192
|
+
|------|----------|------|----------|
|
|
193
|
+
| `toOrdered()` | `OrderedCollectable<E>` | ์ ๋ ฌ๋ ์ปฌ๋ ์
์ผ๋ก ๋ณํ | ์ ๋ ฌ ์ฐ์ฐ, ๋ฎ์ ์ฑ๋ฅ |
|
|
194
|
+
| `toUnordered()` | `UnorderedCollectable<E>` | ๋น์ ๋ ฌ ์ปฌ๋ ์
์ผ๋ก ๋ณํ | ๊ฐ์ฅ ๋น ๋ฆ, ์ ๋ ฌ ์์ |
|
|
195
|
+
| `toWindow()` | `WindowCollectable<E>` | ์๋์ฐ ์ปฌ๋ ์
์ผ๋ก ๋ณํ | ์ ๋ ฌ ์ฐ์ฐ, ๋ฎ์ ์ฑ๋ฅ |
|
|
196
|
+
| `toNumericStatistics()` | `Statistics<E, number>` | ์ซ์ ํต๊ณ ๋ถ์ | ์ ๋ ฌ ์ฐ์ฐ, ๋ฎ์ ์ฑ๋ฅ |
|
|
197
|
+
| `toBigintStatistics()` | `Statistics<E, bigint>` | Big integer ํต๊ณ ๋ถ์ | ์ ๋ ฌ ์ฐ์ฐ, ๋ฎ์ ์ฑ๋ฅ |
|
|
198
|
+
| `sorted()` | `OrderedCollectable<E>` | ์์ฐ ์ ๋ ฌ | ์ฌ์ง์ ๊ฒฐ๊ณผ ์ฌ์ ์ |
|
|
199
|
+
| `sorted(comparator)` | `OrderedCollectable<E>` | ์ฌ์ฉ์ ์ ์ ์ ๋ ฌ | ์ฌ์ง์ ๊ฒฐ๊ณผ ์ฌ์ ์ |
|
|
150
200
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
- `UnorderedCollectable<E>` โ ์ ๋ ฌ ์์, ๊ฐ์ฅ ๋น ๋ฆ
|
|
155
|
-
- `WindowCollectable<E>` โ ์ฌ๋ผ์ด๋ฉ ์๋์ฐ
|
|
156
|
-
- `Statistics<E, D>` โ ํต๊ณ ์ง๊ณ
|
|
201
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
202
|
+
```typescript
|
|
203
|
+
import { from } from 'semantic-typescript';
|
|
157
204
|
|
|
158
|
-
|
|
205
|
+
const semanticStream = from([5, 2, 8, 1, 9, 3, 7, 4, 6]);
|
|
159
206
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
| `count()` | ์์ ๊ฐ์ | `.count()` |
|
|
163
|
-
| `toArray()` | ๋ฐฐ์ด๋ก ๋ณํ | `.toArray()` |
|
|
164
|
-
| `toSet()` | Set์ผ๋ก ๋ณํ | `.toSet()` |
|
|
165
|
-
| `toMap(k, v)` | Map์ผ๋ก ๋ณํ | `.toMap(x => x.id, x => x)` |
|
|
166
|
-
| `group(k)` | ํค๋ก ๊ทธ๋ฃนํ | `.group(x => x.category)` |
|
|
167
|
-
| `findAny()` | ์์์ ์์ (Optional) | `.findAny()` |
|
|
168
|
-
| `findFirst()` | ์ฒซ ๋ฒ์งธ ์์ (Optional) | `.findFirst()` |
|
|
169
|
-
| `reduce(...)` | ์ปค์คํ
์ถ์ฝ | `.reduce((a,b) => a + b, 0)` |
|
|
207
|
+
// ์ ๋ ฌ๋ ์ปฌ๋ ์
์ผ๋ก ๋ณํ (๋ฎ์ ์ฑ๋ฅ)
|
|
208
|
+
const ordered = semanticStream.toOrdered();
|
|
170
209
|
|
|
171
|
-
|
|
210
|
+
// ๋น์ ๋ ฌ ์ปฌ๋ ์
์ผ๋ก ๋ณํ (๊ฐ์ฅ ๋น ๋ฆ)
|
|
211
|
+
const unordered = semanticStream.toUnordered();
|
|
172
212
|
|
|
173
|
-
|
|
213
|
+
// ์์ฐ ์ ๋ ฌ
|
|
214
|
+
const sortedNatural = semanticStream.sorted();
|
|
174
215
|
|
|
175
|
-
|
|
216
|
+
// ์ฌ์ฉ์ ์ ์ ์ ๋ ฌ
|
|
217
|
+
const sortedCustom = semanticStream.sorted((a, b) => b - a); // ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ
|
|
176
218
|
|
|
177
|
-
|
|
219
|
+
// ํต๊ณ ๊ฐ์ฒด๋ก ๋ณํ
|
|
220
|
+
const stats = semanticStream.toNumericStatistics();
|
|
178
221
|
|
|
179
|
-
|
|
180
|
-
const sorted = new OrderedCollectable(stream);
|
|
181
|
-
const customSorted = new OrderedCollectable(stream, (a, b) => b - a);
|
|
222
|
+
// ์ฐธ๊ณ : ์ ๋ฉ์๋๋ค์ Semantic ์ธ์คํด์ค๋ฅผ ํตํด ํธ์ถํ์ฌ Collectable์ ์ป์ ํ ํฐ๋ฏธ๋ ๋ฉ์๋ ์ฌ์ฉ ํ์
|
|
182
223
|
```
|
|
183
224
|
|
|
184
|
-
|
|
225
|
+
### Collector<E, A, R> - ๋ฐ์ดํฐ ์์ง๊ธฐ
|
|
185
226
|
|
|
186
|
-
|
|
227
|
+
์์ง๊ธฐ๋ ์คํธ๋ฆผ ๋ฐ์ดํฐ๋ฅผ ํน์ ๊ตฌ์กฐ๋ก ์ง๊ณํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
|
|
187
228
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
229
|
+
| ๋ฉ์๋ | ์ค๋ช
| ์ฌ์ฉ ์๋๋ฆฌ์ค |
|
|
230
|
+
|------|------|----------|
|
|
231
|
+
| `collect(generator)` | ๋ฐ์ดํฐ ์์ง ์คํ | ์คํธ๋ฆผ ํฐ๋ฏธ๋ ์ฐ์ฐ |
|
|
232
|
+
| `static full(identity, accumulator, finisher)` | ์์ ํ ์์ง๊ธฐ ์์ฑ | ์์ ํ ์ฒ๋ฆฌ ํ์ |
|
|
233
|
+
| `static shortable(identity, interruptor, accumulator, finisher)` | ์ค๋จ ๊ฐ๋ฅ ์์ง๊ธฐ ์์ฑ | ์กฐ๊ธฐ ์ข
๋ฃ ๊ฐ๋ฅ |
|
|
191
234
|
|
|
235
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
192
236
|
```typescript
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
237
|
+
import { Collector } from 'semantic-typescript';
|
|
238
|
+
|
|
239
|
+
// ์ฌ์ฉ์ ์ ์ ์์ง๊ธฐ ์์ฑ
|
|
240
|
+
const sumCollector = Collector.full(
|
|
241
|
+
() => 0, // ์ด๊ธฐ ๊ฐ
|
|
242
|
+
(acc, value) => acc + value, // ๋์ฐ๊ธฐ
|
|
243
|
+
result => result // ์๋ฃ ํจ์
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
// ์์ง๊ธฐ ์ฌ์ฉ (Semantic์์ Collectable๋ก ๋ณํ ํ์)
|
|
247
|
+
const numbers = from([1, 2, 3, 4, 5]);
|
|
248
|
+
const sum = numbers.toUnordered().collect(sumCollector); // 15
|
|
196
249
|
```
|
|
197
250
|
|
|
198
|
-
|
|
199
|
-
โ
**์์๊ฐ ์ค์ํ์ง ์์ ๋ ์ต๊ณ ์ ์ฑ๋ฅ**
|
|
200
|
-
|
|
201
|
-
---
|
|
251
|
+
### Collectable<E> - ์์ง ๊ฐ๋ฅ ๋ฐ์ดํฐ ์ถ์ ํด๋์ค
|
|
202
252
|
|
|
203
|
-
|
|
253
|
+
ํ๋ถํ ๋ฐ์ดํฐ ์ง๊ณ ๋ฐ ๋ณํ ๋ฉ์๋๋ฅผ ์ ๊ณตํฉ๋๋ค. **์ฐธ๊ณ : ๋ฐ๋์ Semantic ์ธ์คํด์ค๋ฅผ ํตํด sorted(), toOrdered() ๋ฑ์ ๋จผ์ ํธ์ถํ์ฌ Collectable ์ธ์คํด์ค๋ฅผ ์ป์ ํ ๋ค์ ๋ฉ์๋๋ค์ ์ฌ์ฉํด์ผ ํฉ๋๋ค.**
|
|
204
254
|
|
|
205
|
-
|
|
255
|
+
#### ๋ฐ์ดํฐ ์ฟผ๋ฆฌ ์ฐ์ฐ
|
|
206
256
|
|
|
207
|
-
|
|
257
|
+
| ๋ฉ์๋ | ๋ฐํ ํ์
| ์ค๋ช
| ์์ |
|
|
258
|
+
|------|----------|------|------|
|
|
259
|
+
| `anyMatch(predicate)` | `boolean` | ์ด๋ค ์์๋ผ๋ ์ผ์นํ๋์ง ์ฌ๋ถ | `anyMatch(x => x > 0)` |
|
|
260
|
+
| `allMatch(predicate)` | `boolean` | ๋ชจ๋ ์์๊ฐ ์ผ์นํ๋์ง ์ฌ๋ถ | `allMatch(x => x > 0)` |
|
|
261
|
+
| `count()` | `bigint` | ์์ ์ ํต๊ณ | `count()` โ `5n` |
|
|
262
|
+
| `isEmpty()` | `boolean` | ์คํธ๋ฆผ์ด ๋น์ด ์๋์ง ์ฌ๋ถ | `isEmpty()` |
|
|
263
|
+
| `findAny()` | `Optional<E>` | ์๋ฌด ์์ ์ฐพ๊ธฐ | `findAny()` |
|
|
264
|
+
| `findFirst()` | `Optional<E>` | ์ฒซ ๋ฒ์งธ ์์ ์ฐพ๊ธฐ | `findFirst>` |
|
|
265
|
+
| `findLast()` | `Optional<E>` | ๋ง์ง๋ง ์์ ์ฐพ๊ธฐ | `findLast>` |
|
|
208
266
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
##### ์ฃผ์ ํต๊ณ ๋ฉ์๋:
|
|
267
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
268
|
+
```typescript
|
|
269
|
+
import { from } from 'semantic-typescript';
|
|
213
270
|
|
|
214
|
-
|
|
215
|
-
|--------|------|------|
|
|
216
|
-
| `mean()` | ํ๊ท | `.mean()` |
|
|
217
|
-
| `median()` | ์ค์๊ฐ | `.median()` |
|
|
218
|
-
| `mode()` | ์ต๋น๊ฐ | `.mode()` |
|
|
219
|
-
| `minimum()` | ์ต์๊ฐ | `.minimum()` |
|
|
220
|
-
| `maximum()` | ์ต๋๊ฐ | `.maximum()` |
|
|
221
|
-
| `range()` | ์ต๋๊ฐ - ์ต์๊ฐ | `.range()` |
|
|
222
|
-
| `variance()` | ๋ถ์ฐ | `.variance()` |
|
|
223
|
-
| `standardDeviation()` | ํ์ค ํธ์ฐจ | `.standardDeviation()` |
|
|
224
|
-
| `summate()` | ํฉ๊ณ | `.summate()` |
|
|
225
|
-
| `quantile(q)` | q๋ถ์์ (0~1) | `.quantile(0.5)` โ ์ค์๊ฐ |
|
|
226
|
-
| `frequency()` | ๋น๋ ๋งต | `.frequency()` |
|
|
271
|
+
const numbers = from([1, 2, 3, 4, 5]);
|
|
227
272
|
|
|
228
|
-
|
|
273
|
+
// ํฐ๋ฏธ๋ ๋ฉ์๋ ์ฌ์ฉ ์ ๋ฐ๋์ Collectable๋ก ๋ณํ
|
|
274
|
+
const collectable = numbers.toUnordered();
|
|
229
275
|
|
|
230
|
-
|
|
276
|
+
// ๋ฐ์ดํฐ ์ฟผ๋ฆฌ ์ฐ์ฐ
|
|
277
|
+
const hasEven = collectable.anyMatch(x => x % 2 === 0); // true
|
|
278
|
+
const allPositive = collectable.allMatch(x => x > 0); // true
|
|
279
|
+
const count = collectable.count(); // 5n
|
|
280
|
+
const isEmpty = collectable.isEmpty(); // false
|
|
281
|
+
const firstElement = collectable.findFirst(); // Optional.of(1)
|
|
282
|
+
const anyElement = collectable.findAny(); // ์๋ฌด ์์
|
|
283
|
+
```
|
|
231
284
|
|
|
285
|
+
#### ๋ฐ์ดํฐ ์ง๊ณ ์ฐ์ฐ
|
|
286
|
+
|
|
287
|
+
| ๋ฉ์๋ | ๋ฐํ ํ์
| ์ค๋ช
| ๋ณต์ก๋ |
|
|
288
|
+
|------|----------|------|--------|
|
|
289
|
+
| `group(classifier)` | `Map<K, E[]>` | ๋ถ๋ฅ์์ ๋ฐ๋ฅธ ๊ทธ๋ฃนํ | O(n) |
|
|
290
|
+
| `groupBy(keyExtractor, valueExtractor)` | `Map<K, V[]>` | ํค-๊ฐ ์ถ์ถ๊ธฐ์ ๋ฐ๋ฅธ ๊ทธ๋ฃนํ | O(n) |
|
|
291
|
+
| `join()` | `string` | ๋ฌธ์์ด๋ก ๊ฒฐํฉ | O(n) |
|
|
292
|
+
| `join(delimiter)` | `string` | ๊ตฌ๋ถ์๋ก ๊ฒฐํฉ | O(n) |
|
|
293
|
+
| `partition(count)` | `E[][]` | ๊ฐ์์ ๋ฐ๋ฅธ ๋ถํ | O(n) |
|
|
294
|
+
| `partitionBy(classifier)` | `E[][]` | ๋ถ๋ฅ์์ ๋ฐ๋ฅธ ๋ถํ | O(n) |
|
|
295
|
+
| `reduce(accumulator)` | `Optional<E>` | ์ถ์ ์ฐ์ฐ | O(n) |
|
|
296
|
+
| `reduce(identity, accumulator)` | `E` | ์๋ณ์๋ฅผ ์ฌ์ฉํ ์ถ์ | O(n) |
|
|
297
|
+
| `toArray()` | `E[]` | ๋ฐฐ์ด๋ก ๋ณํ | O(n) |
|
|
298
|
+
| `toMap(keyExtractor, valueExtractor)` | `Map<K, V>` | Map์ผ๋ก ๋ณํ | O(n) |
|
|
299
|
+
| `toSet()` | `Set<E>` | Set์ผ๋ก ๋ณํ | O(n) |
|
|
300
|
+
|
|
301
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
232
302
|
```typescript
|
|
233
|
-
import { from
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
//
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
303
|
+
import { from } from 'semantic-typescript';
|
|
304
|
+
|
|
305
|
+
const people = from([
|
|
306
|
+
{ name: "Alice", age: 25, city: "New York" },
|
|
307
|
+
{ name: "Bob", age: 30, city: "London" },
|
|
308
|
+
{ name: "Charlie", age: 25, city: "New York" }
|
|
309
|
+
]);
|
|
310
|
+
|
|
311
|
+
// ์ง๊ณ ์ฐ์ฐ ์ฌ์ฉ ์ ๋ฐ๋์ Collectable๋ก ๋ณํ
|
|
312
|
+
const collectable = people.toUnordered();
|
|
313
|
+
|
|
314
|
+
// ๊ทธ๋ฃนํ ์ฐ์ฐ
|
|
315
|
+
const byCity = collectable.group(person => person.city);
|
|
316
|
+
// Map { "New York" => [{name: "Alice", ...}, {name: "Charlie", ...}], "London" => [{name: "Bob", ...}] }
|
|
317
|
+
|
|
318
|
+
const byAge = collectable.groupBy(
|
|
319
|
+
person => person.age,
|
|
320
|
+
person => person.name
|
|
321
|
+
);
|
|
322
|
+
// Map { 25 => ["Alice", "Charlie"], 30 => ["Bob"] }
|
|
323
|
+
|
|
324
|
+
// ์ปฌ๋ ์
์ผ๋ก ๋ณํ
|
|
325
|
+
const array = collectable.toArray(); // ์๋ณธ ๋ฐฐ์ด
|
|
326
|
+
const set = collectable.toSet(); // Set ์ปฌ๋ ์
|
|
327
|
+
const map = collectable.toMap(
|
|
328
|
+
person => person.name,
|
|
329
|
+
person => person.age
|
|
330
|
+
); // Map { "Alice" => 25, "Bob" => 30, "Charlie" => 25 }
|
|
331
|
+
|
|
332
|
+
// ์ถ์ ์ฐ์ฐ
|
|
333
|
+
const totalAge = collectable.reduce(0, (acc, person) => acc + person.age); // 80
|
|
334
|
+
const oldest = collectable.reduce((a, b) => a.age > b.age ? a : b); // Optional.of({name: "Bob", age: 30, ...})
|
|
253
335
|
```
|
|
254
336
|
|
|
255
|
-
|
|
337
|
+
### ํน์ ์์ง๊ธฐ ๊ตฌํ
|
|
256
338
|
|
|
257
|
-
|
|
339
|
+
#### UnorderedCollectable<E>
|
|
340
|
+
- **ํน์ง**: ๊ฐ์ฅ ๋น ๋ฅธ ์์ง๊ธฐ, ์ ๋ ฌ ์์
|
|
341
|
+
- **์ฌ์ฉ ์๋๋ฆฌ์ค**: ์์ ์ค์ํ์ง ์์, ์ต๋ ์ฑ๋ฅ ์ํ ๋
|
|
342
|
+
- **๋ฉ์๋**: ๋ชจ๋ Collectable ๋ฉ์๋ ์์
|
|
258
343
|
|
|
259
|
-
|
|
344
|
+
#### OrderedCollectable<E>
|
|
345
|
+
- **ํน์ง**: ์์ ์์ ๋ณด์ฅ, ๋ฎ์ ์ฑ๋ฅ
|
|
346
|
+
- **์ฌ์ฉ ์๋๋ฆฌ์ค**: ์ ๋ ฌ๋ ๊ฒฐ๊ณผ ํ์
|
|
347
|
+
- **ํน๋ณ ๋ฉ์๋**: ๋ชจ๋ ๋ฉ์๋ ์์, ๋ด๋ถ ์ ๋ ฌ ์ํ ์ ์ง
|
|
260
348
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
| `useCompare(a, b)` | ๋ฒ์ฉ ๋น๊ต ํจ์ |
|
|
268
|
-
| `useRandom(x)` | ์์ฌ ๋์ ์์ฑ๊ธฐ (์ฌ๋ฏธ์ผ์) |
|
|
349
|
+
#### WindowCollectable<E>
|
|
350
|
+
- **ํน์ง**: ์ฌ๋ผ์ด๋ฉ ์๋์ฐ ์ฐ์ฐ ์ง์
|
|
351
|
+
- **์ฌ์ฉ ์๋๋ฆฌ์ค**: ์๊ณ์ด ๋ฐ์ดํฐ ๋ถ์
|
|
352
|
+
- **ํน๋ณ ๋ฉ์๋**:
|
|
353
|
+
- `slide(size, step)` - ์ฌ๋ผ์ด๋ฉ ์๋์ฐ
|
|
354
|
+
- `tumble(size)` - ํ
๋ธ๋ง ์๋์ฐ
|
|
269
355
|
|
|
270
|
-
|
|
356
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
357
|
+
```typescript
|
|
358
|
+
import { from } from 'semantic-typescript';
|
|
271
359
|
|
|
272
|
-
|
|
360
|
+
const data = from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
273
361
|
|
|
274
|
-
|
|
362
|
+
// ๋น์ ๋ ฌ ์์ง๊ธฐ (๊ฐ์ฅ ๋น ๋ฆ)
|
|
363
|
+
const unordered = data.toUnordered();
|
|
364
|
+
const unorderedArray = unordered.toArray(); // ์๋ณธ ์์ ์ ์ง ๊ฐ๋ฅ [1, 2, 3, ...]
|
|
275
365
|
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
accept(i, BigInt(i));
|
|
280
|
-
if (i === 5) interrupt(i);
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
const s = new Semantic(gen);
|
|
285
|
-
```
|
|
366
|
+
// ์ ๋ ฌ ์์ง๊ธฐ
|
|
367
|
+
const ordered = data.toOrdered();
|
|
368
|
+
const orderedArray = ordered.toArray(); // ์ ๋ ฌ ๋ณด์ฅ [1, 2, 3, ...]
|
|
286
369
|
|
|
287
|
-
|
|
370
|
+
// ์๋์ฐ ์์ง๊ธฐ
|
|
371
|
+
const windowed = data.toWindow();
|
|
372
|
+
const slidingWindows = windowed.slide(3n, 2n); // ์๋์ฐ ํฌ๊ธฐ 3, ๋จ๊ณ 2
|
|
373
|
+
// ์๋์ฐ 1: [1, 2, 3], ์๋์ฐ 2: [3, 4, 5], ์๋์ฐ 3: [5, 6, 7], ...
|
|
288
374
|
|
|
289
|
-
|
|
290
|
-
|
|
375
|
+
const tumblingWindows = windowed.tumble(4n); // ํ
๋ธ๋ง ์๋์ฐ ํฌ๊ธฐ 4
|
|
376
|
+
// ์๋์ฐ 1: [1, 2, 3, 4], ์๋์ฐ 2: [5, 6, 7, 8], ...
|
|
291
377
|
```
|
|
292
378
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
379
|
+
### Statistics<E, D> - ํต๊ณ ๋ถ์
|
|
380
|
+
|
|
381
|
+
ํต๊ณ ๋ถ์ ๊ธฐ๋ณธ ํด๋์ค๋ก ํ๋ถํ ํต๊ณ ๊ณ์ฐ ๋ฉ์๋๋ฅผ ์ ๊ณตํฉ๋๋ค. **์ฐธ๊ณ : ๋ฐ๋์ Semantic ์ธ์คํด์ค๋ฅผ ํตํด toNumericStatistics() ๋๋ toBigIntStatistics()๋ฅผ ํธ์ถํ์ฌ Statistics ์ธ์คํด์ค๋ฅผ ์ป์ ํ ๋ค์ ๋ฉ์๋๋ค์ ์ฌ์ฉํด์ผ ํฉ๋๋ค.**
|
|
382
|
+
|
|
383
|
+
#### ํต๊ณ ๊ณ์ฐ ์ฐ์ฐ
|
|
384
|
+
|
|
385
|
+
| ๋ฉ์๋ | ๋ฐํ ํ์
| ์ค๋ช
| ์๊ณ ๋ฆฌ์ฆ ๋ณต์ก๋ |
|
|
386
|
+
|------|----------|------|------------|
|
|
387
|
+
| `maximum()` | `Optional<E>` | ์ต๋๊ฐ | O(n) |
|
|
388
|
+
| `minimum()` | `Optional<E>` | ์ต์๊ฐ | O(n) |
|
|
389
|
+
| `range()` | `D` | ๋ฒ์ (์ต๋-์ต์) | O(n) |
|
|
390
|
+
| `variance()` | `D` | ๋ถ์ฐ | O(n) |
|
|
391
|
+
| `standardDeviation()` | `D` | ํ์ค ํธ์ฐจ | O(n) |
|
|
392
|
+
| `mean()` | `D` | ํ๊ท ๊ฐ | O(n) |
|
|
393
|
+
| `median()` | `D` | ์ค์๊ฐ | O(n log n) |
|
|
394
|
+
| `mode()` | `D` | ์ต๋น๊ฐ | O(n) |
|
|
395
|
+
| `frequency()` | `Map<D, bigint>` | ๋น๋ ๋ถํฌ | O(n) |
|
|
396
|
+
| `summate()` | `D` | ํฉ๊ณ | O(n) |
|
|
397
|
+
| `quantile(quantile)` | `D` | ๋ถ์์ | O(n log n) |
|
|
398
|
+
| `interquartileRange()` | `D` | ์ฌ๋ถ์ ๋ฒ์ | O(n log n) |
|
|
399
|
+
| `skewness()` | `D` | ์๋ | O(n) |
|
|
400
|
+
| `kurtosis()` | `D` | ์ฒจ๋ | O(n) |
|
|
401
|
+
|
|
402
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
403
|
+
```typescript
|
|
404
|
+
import { from } from 'semantic-typescript';
|
|
405
|
+
|
|
406
|
+
const numbers = from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
407
|
+
|
|
408
|
+
// ํต๊ณ ๋ฉ์๋ ์ฌ์ฉ ์ ๋ฐ๋์ ํต๊ณ ๊ฐ์ฒด๋ก ๋ณํ
|
|
409
|
+
const stats = numbers.toNumericStatistics();
|
|
410
|
+
|
|
411
|
+
// ๊ธฐ๋ณธ ํต๊ณ
|
|
412
|
+
const count = stats.count(); // 10n
|
|
413
|
+
const max = stats.maximum(); // Optional.of(10)
|
|
414
|
+
const min = stats.minimum(); // Optional.of(1)
|
|
415
|
+
const range = stats.range(); // 9
|
|
416
|
+
const mean = stats.mean(); // 5.5
|
|
417
|
+
const median = stats.median(); // 5.5
|
|
418
|
+
const sum = stats.summate(); // 55
|
|
419
|
+
|
|
420
|
+
// ๊ณ ๊ธ ํต๊ณ
|
|
421
|
+
const variance = stats.variance(); // 8.25
|
|
422
|
+
const stdDev = stats.standardDeviation(); // 2.872
|
|
423
|
+
const mode = stats.mode(); // ์ด๋ค ๊ฐ (๋ชจ๋ ํ ๋ฒ์ฉ ๋ํ๋๋ฏ๋ก)
|
|
424
|
+
const q1 = stats.quantile(0.25); // 3.25
|
|
425
|
+
const q3 = stats.quantile(0.75); // 7.75
|
|
426
|
+
const iqr = stats.interquartileRange(); // 4.5
|
|
427
|
+
|
|
428
|
+
// ๋น๋ ๋ถํฌ
|
|
429
|
+
const freq = stats.frequency(); // Map {1 => 1n, 2 => 1n, ...}
|
|
430
|
+
```
|
|
298
431
|
|
|
299
|
-
|
|
432
|
+
#### ํน์ ํต๊ณ ๊ตฌํ ํด๋์ค
|
|
300
433
|
|
|
301
|
-
|
|
434
|
+
**NumericStatistics<E>**
|
|
435
|
+
- number ํ์
ํต๊ณ ๋ถ์ ์ฒ๋ฆฌ
|
|
436
|
+
- ๋ชจ๋ ํต๊ณ ๊ณ์ฐ์ด number ํ์
๋ฐํ
|
|
302
437
|
|
|
303
|
-
|
|
438
|
+
**BigIntStatistics<E>**
|
|
439
|
+
- bigint ํ์
ํต๊ณ ๋ถ์ ์ฒ๋ฆฌ
|
|
440
|
+
- ๋ชจ๋ ํต๊ณ ๊ณ์ฐ์ด bigint ํ์
๋ฐํ
|
|
304
441
|
|
|
305
|
-
|
|
442
|
+
**์ฝ๋ ์์ ๋ณด์ถฉ:**
|
|
443
|
+
```typescript
|
|
444
|
+
import { from } from 'semantic-typescript';
|
|
306
445
|
|
|
307
|
-
|
|
446
|
+
// ์ซ์ ํต๊ณ
|
|
447
|
+
const numberData = from([10, 20, 30, 40, 50]);
|
|
448
|
+
const numericStats = numberData.toNumericStatistics();
|
|
308
449
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
| null/undefined ์์ ํ๊ฒ ์ฒ๋ฆฌ | `Optional<T>` |
|
|
312
|
-
| ์คํธ๋ฆผ ์์ฑ | `from([...])`, `range()`, `fill()` |
|
|
313
|
-
| ๋ฐ์ดํฐ ๋ณํ | `map()`, `filter()` |
|
|
314
|
-
| ๋ฐ์ดํฐ ์ ๋ ฌ | `sorted()`, `toOrdered()` |
|
|
315
|
-
| ์ ๋ ฌ ์์ (๊ฐ์ฅ ๋น ๋ฆ) | `toUnordered()` โ
|
|
|
316
|
-
| ๊ทธ๋ฃนํ / ์ง๊ณ | `toMap()`, `group()`, `Collector` |
|
|
317
|
-
| ํต๊ณ | `NumericStatistics`, `mean()`, `median()` ๋ฑ |
|
|
450
|
+
console.log(numericStats.mean()); // 30
|
|
451
|
+
console.log(numericStats.summate()); // 150
|
|
318
452
|
|
|
319
|
-
|
|
453
|
+
// Big integer ํต๊ณ
|
|
454
|
+
const bigintData = from([100n, 200n, 300n, 400n, 500n]);
|
|
455
|
+
const bigintStats = bigintData.toBigIntStatistics();
|
|
320
456
|
|
|
321
|
-
|
|
457
|
+
console.log(bigintStats.mean()); // 300n
|
|
458
|
+
console.log(bigintStats.summate()); // 1500n
|
|
322
459
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
460
|
+
// ๋งคํผ ํจ์๋ฅผ ์ฌ์ฉํ ํต๊ณ
|
|
461
|
+
const objectData = from([
|
|
462
|
+
{ value: 15 },
|
|
463
|
+
{ value: 25 },
|
|
464
|
+
{ value: 35 },
|
|
465
|
+
{ value: 45 }
|
|
466
|
+
]);
|
|
326
467
|
|
|
327
|
-
|
|
468
|
+
const objectStats = objectData.toNumericStatistics();
|
|
469
|
+
const meanWithMapper = objectStats.mean(obj => obj.value); // 30
|
|
470
|
+
const sumWithMapper = objectStats.summate(obj => obj.value); // 120
|
|
471
|
+
```
|
|
328
472
|
|
|
329
|
-
|
|
473
|
+
## ์์ ํ ์ฌ์ฉ ์์
|
|
330
474
|
|
|
331
|
-
|
|
475
|
+
```typescript
|
|
476
|
+
import { from, validate, invalidate } from 'semantic-typescript';
|
|
477
|
+
|
|
478
|
+
// 1. ๋ฐ์ดํฐ ์คํธ๋ฆผ ์์ฑ
|
|
479
|
+
const rawData = [5, 2, 8, 1, null, 9, 3, undefined, 7, 4, 6];
|
|
480
|
+
const semanticStream = from(rawData);
|
|
481
|
+
|
|
482
|
+
// 2. ์คํธ๋ฆผ ์ฒ๋ฆฌ ํ์ดํ๋ผ์ธ
|
|
483
|
+
const processedStream = semanticStream
|
|
484
|
+
.filter(val => validate(val)) // null ๋ฐ undefined ํํฐ๋ง
|
|
485
|
+
.map(val => val! * 2) // ๊ฐ ๊ฐ์ 2 ๊ณฑํ๊ธฐ (validate๊ฐ ๋น์ด์์ง ์์์ ๋ณด์ฅํ๋ฏ๋ก ! ์ฌ์ฉ)
|
|
486
|
+
.distinct(); // ์ค๋ณต ์ ๊ฑฐ
|
|
487
|
+
|
|
488
|
+
// 3. Collectable๋ก ๋ณํ ๋ฐ ํฐ๋ฏธ๋ ์ฐ์ฐ ์ฌ์ฉ
|
|
489
|
+
const collectable = processedStream.toUnordered();
|
|
490
|
+
|
|
491
|
+
// 4. ๋ฐ์ดํฐ ๊ฒ์ฆ ๋ฐ ์ฌ์ฉ
|
|
492
|
+
if (!collectable.isEmpty()) {
|
|
493
|
+
const results = collectable
|
|
494
|
+
.filter(x => x > 5) // ๋ค์ ํํฐ๋ง
|
|
495
|
+
.toArray(); // ๋ฐฐ์ด๋ก ๋ณํ
|
|
496
|
+
|
|
497
|
+
console.log("์ฒ๋ฆฌ ๊ฒฐ๊ณผ:", results); // [16, 18, 14, 8, 12]
|
|
498
|
+
|
|
499
|
+
// ํต๊ณ ์ ๋ณด
|
|
500
|
+
const stats = processedStream.toNumericStatistics();
|
|
501
|
+
console.log("ํ๊ท ๊ฐ:", stats.mean()); // 11.2
|
|
502
|
+
console.log("์ดํฉ:", stats.summate()); // 56
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// 5. ์ ์ฌ์ ์ผ๋ก ๋ฌดํจํ ๋ฐ์ดํฐ ์ฒ๋ฆฌ
|
|
506
|
+
const potentiallyInvalidData: Array<number | null> = [1, null, 3, 4, null];
|
|
507
|
+
const validData = potentiallyInvalidData.filter(validate);
|
|
508
|
+
const invalidData = potentiallyInvalidData.filter(invalidate);
|
|
509
|
+
|
|
510
|
+
console.log("์ ํจํ ๋ฐ์ดํฐ:", validData); // [1, 3, 4]
|
|
511
|
+
console.log("๋ฌดํจํ ๋ฐ์ดํฐ:", invalidData); // [null, null]
|
|
512
|
+
```
|
|
332
513
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
514
|
+
## ์ค์ํ ์ฌ์ฉ ๊ท์น ์์ฝ
|
|
515
|
+
|
|
516
|
+
1. **์คํธ๋ฆผ ์์ฑ**: `from()`, `range()`, `fill()` ๋ฑ ํฉํ ๋ฆฌ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ Semantic ์ธ์คํด์ค ์์ฑ
|
|
517
|
+
2. **์คํธ๋ฆผ ๋ณํ**: Semantic ์ธ์คํด์ค์์ `map()`, `filter()`, `distinct()` ๋ฑ ๋ฉ์๋ ํธ์ถ
|
|
518
|
+
3. **Collectable๋ก ๋ณํ**: ๋ฐ๋์ Semantic ์ธ์คํด์ค๋ฅผ ํตํด ๋ค์ ๋ฉ์๋ ์ค ํ๋ ํธ์ถ:
|
|
519
|
+
- `toOrdered()` - ์ ๋ ฌ ์์ง๊ธฐ
|
|
520
|
+
- `toUnordered()` - ๋น์ ๋ ฌ ์์ง๊ธฐ (๊ฐ์ฅ ๋น ๋ฆ)
|
|
521
|
+
- `toWindow()` - ์๋์ฐ ์์ง๊ธฐ
|
|
522
|
+
- `toNumericStatistics()` - ์ซ์ ํต๊ณ
|
|
523
|
+
- `toBigIntStatistics()` - Big integer ํต๊ณ
|
|
524
|
+
- `sorted()` - ์์ฐ ์ ๋ ฌ
|
|
525
|
+
- `sorted(comparator)` - ์ฌ์ฉ์ ์ ์ ์ ๋ ฌ
|
|
526
|
+
4. **ํฐ๋ฏธ๋ ์ฐ์ฐ**: Collectable ์ธ์คํด์ค์์ `toArray()`, `count()`, `summate()` ๋ฑ ํฐ๋ฏธ๋ ๋ฉ์๋ ํธ์ถ
|
|
527
|
+
5. **๋ฐ์ดํฐ ๊ฒ์ฆ**: `validate()`๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ๊ฐ null/undefined๊ฐ ์๋์ ๋ณด์ฅ, `invalidate()`๋ฅผ ์ฌ์ฉํ์ฌ ๋ฌดํจํ ๋ฐ์ดํฐ ํ์ธ
|
|
528
|
+
|
|
529
|
+
์ด ์ค๊ณ๋ ํ์
์์ ์ฑ๊ณผ ์ฑ๋ฅ ์ต์ ํ๋ฅผ ๋ณด์ฅํ๋ฉด์ ํ๋ถํ ์คํธ๋ฆผ ์ฒ๋ฆฌ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค.
|