Skip to content

Commit c688a44

Browse files
committed
update
1 parent e684c6b commit c688a44

10 files changed

Lines changed: 119 additions & 98 deletions

File tree

_site/0-book/unit-2/section-6/0-functor-monad.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ This unified view reveals an elegant symmetry in how we can obtain our desired m
2626
- The **Monad** approach (lower path) obtains `g` by using `bind` to transform a Kleisli arrow `f` into a container mapper function `g` / `bind f`
2727

2828
Both paths provide us with what we ultimately want - a function `g` that can map between containers. The difference lies in our starting point: we can begin with either a regular function or a Kleisli arrow, and both paths will lead us to the container mapper function we seek.
29+
2930
:::

_site/0-book/unit-5/section-3/1-map.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const numbers = Timeline(5);
2222
// Pass a function: (x: number) => string
2323
const labels = numbers.map(x => `Score: ${x}`);
2424

25-
console.log(labels.at(Now)); // "Score: 5"
25+
console.log(labels.at(Now)); // "Score: 5"share
2626

2727
// When the source is updated, labels is automatically updated as well
2828
numbers.define(Now, 100);
@@ -35,19 +35,7 @@ When you call `map`, a **Dependency** is registered internally between the two `
3535

3636
The dependency created by `map` is **Static**. Once you define the relationship `labels = numbers.map(...)`, the rule itself—the transformation of the value—does not change later.
3737

38-
```d2
39-
Documentation -> Website: Starlight
40-
```
41-
42-
```txt
43-
+-----------------+ .map(x => `Score: ${x}`) +-----------------+
44-
| numbers | --------------------------------> | labels |
45-
| (Timeline<number>) | | (Timeline<string>) |
46-
+-----------------+ +-----------------+
47-
^ |
48-
| .define(Now, 100) V
49-
+------------- Value propagates to "Score: 100"
50-
```
38+
![image](https://raw.githubusercontent.com/ken-okabe/web-images5/main/img_1752494846714.png)
5139

5240
This simple concept of a "static dependency" is the foundation for understanding the "dynamic" dependencies constructed by `bind` and `using`, which will be introduced later.
5341

@@ -88,16 +76,16 @@ console.log(labels.at(Now)); // "Score: 5"
8876
// ソースを更新すると、labelsも自動的に更新される
8977
numbers.define(Now, 100);
9078
console.log(labels.at(Now)); // "Score: 100"
79+
```txt```txt
80+
+-----------------+ .map(x => `Score: ${x}`) +-----------------+
81+
| numbers | --------------------------------> | labels |
82+
| (Timeline<number>) | | (Timeline<string>) |
83+
+-----------------+ +-----------------+
84+
^ |
85+
| .define(Now, 100) V
86+
+------------- 値が"Score: 100"へ伝播
9187

9288
```
93-
94-
## 依存グラフ (Dependency Graph)
95-
96-
`map`を呼び出すと、内部では2つの`Timeline`の間に**依存関係 (Dependency)** が登録されます。この関係性のネットワーク全体を**依存グラフ**と呼びます。
97-
98-
`map`が作る依存関係は**静的 (Static)** です。一度`labels = numbers.map(...)`という関係を定義したら、`numbers``labels`の間の「値を変換する」というルールそのものが後から変わることはありません。
99-
100-
```txt
10189
+-----------------+ .map(x => `Score: ${x}`) +-----------------+
10290
| numbers | --------------------------------> | labels |
10391
| (Timeline<number>) | | (Timeline<string>) |
@@ -107,6 +95,16 @@ console.log(labels.at(Now)); // "Score: 100"
10795
+------------- 値が"Score: 100"へ伝播
10896

10997
```
98+
```
99+
100+
## 依存グラフ (Dependency Graph)
101+
102+
`map`を呼び出すと、内部では2つの`Timeline`の間に**依存関係 (Dependency)** が登録されます。この関係性のネットワーク全体を**依存グラフ**と呼びます。
103+
104+
`map`が作る依存関係は**静的 (Static)** です。一度`labels = numbers.map(...)`という関係を定義したら、`numbers``labels`の間の「値を変換する」というルールそのものが後から変わることはありません。
105+
106+
![image](https://raw.githubusercontent.com/ken-okabe/web-images5/main/img_1752494846714.png)
107+
110108

111109
このシンプルな「静的な依存関係」の概念が、後に出てくる`bind``using`が構築する「動的な」依存関係を理解するための基礎となります。
112110

_site/0-book/unit-5/section-3/3-bind.md

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,25 @@ The benefits of this `bind` approach are numerous.
121121

122122
As a common approach, trying to define `B` and `C` separately with `.map` and then combining them to create `D` gives rise to the "problematic structure" of a diamond. However, by using `bind`, the dependency graph changes fundamentally.
123123

124-
Plaintext
125124

126-
```
127-
+-----------+ .bind(a => { return Timeline(d); }) +-----------+
128-
| Timeline A| ------------------------------------------> | Timeline D|
129-
+-----------+ +-----------+
130-
```
125+
![image](https://raw.githubusercontent.com/ken-okabe/web-images5/main/img_1752493931653.png)
131126

132127
There are no longer intermediate `timelineB` or `timelineC`, and the diamond structure itself is never formed. Therefore, problems like glitches and multiple updates **cannot structurally occur**. This is a solution on a different level: not fixing a problem after it occurs, but **choosing a superior design where the problem does not arise**.
133128

129+
![image](https://raw.githubusercontent.com/ken-okabe/web-images5/main/img_1745716642404.png)
130+
131+
132+
#### 2. Execution Efficiency
133+
134+
In this structure, every time `A` is updated, the function passed to `bind` is executed only once, and `D` is calculated only once. This is highly efficient.
135+
136+
#### 3. Complete Elimination of Transactional Processing
137+
138+
Even more importantly, the **complex
139+
134140
#### 2. Execution Efficiency
135141

136-
In this structure, every time `A` is updated, the function passed to `bind` is executed only once, and `D` is calculated only once. This is highly efficient.
142+
In this structure, every time `A` is updated, the function passed to `bind` is executed only once, and `D` is calculated only once. This is highly efficient.
137143

138144
#### 3. Complete Elimination of Transactional Processing
139145

@@ -317,7 +323,17 @@ let B = A + 1; // 期待値: 11
317323
let C = A * 2; // 期待値: 20
318324
let D = B + C; // 期待値: 31
319325
```
320-
326+
[main e684c6b] update
327+
2 files changed, 8 insertions(+)
328+
Enumerating objects: 7, done.
329+
Counting objects: 100% (7/7), done.
330+
Delta compression using up to 16 threads
331+
Compressing objects: 100% (4/4), done.
332+
Writing objects: 100% (4/4), 575 bytes | 575.00 KiB/s, done.
333+
Total 4 (delta 3), reused 0 (delta 0), pack-reused 0 (from 0)
334+
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
335+
To https://github.com/ken-okabe/ken-okabe.github.io
336+
6660b97..e684c6b main -> main
321337
しかし、更新の伝播順序によっては、グリッチが発生します。
322338

323339
1. `B` が先に更新されると、`D``B` の新しい値(`11`)と`C`の古い値(`10`)を使って計算されてしまいます。
@@ -346,7 +362,17 @@ let D = B + C; // 期待値: 31
346362

347363
**Atomic update** を実現している、とも表現されます。
348364

349-
-----
365+
-----[main e684c6b] update
366+
2 files changed, 8 insertions(+)
367+
Enumerating objects: 7, done.
368+
Counting objects: 100% (7/7), done.
369+
Delta compression using up to 16 threads
370+
Compressing objects: 100% (4/4), done.
371+
Writing objects: 100% (4/4), 575 bytes | 575.00 KiB/s, done.
372+
Total 4 (delta 3), reused 0 (delta 0), pack-reused 0 (from 0)
373+
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
374+
To https://github.com/ken-okabe/ken-okabe.github.io
375+
6660b97..e684c6b main -> main
350376

351377
### 3\. Timelineライブラリのアプローチ:「そもそもDiamond問題なんて起こるほうがおかしい」という思想
352378

@@ -380,16 +406,12 @@ const D = A.bind(a => {
380406

381407
一般的なアプローチとして、`.map``B``C`を個別に定義し、それらを合成して`D`を生成しようとすると、ダイアモンドという「問題のある構造」が生まれてしまいます。しかし、`bind`を使うことで、依存グラフは根本的に変わります。
382408

383-
Plaintext
409+
![image](https://raw.githubusercontent.com/ken-okabe/web-images5/main/img_1752493931653.png)
384410

385-
```
386-
+-----------+ .bind(a => { return Timeline(d); }) +-----------+
387-
| Timeline A| ------------------------------------------> | Timeline D|
388-
+-----------+ +-----------+
411+
もはやそこには中間的な`timelineB``timelineC`も存在せず、菱形(ダイアモンド)構造自体が生まれません。したがって、グリッチや複数回更新という問題は**構造的に発生し得ない**のです。これは、発生した問題を後から解決するのではなく、**問題が発生しない優れた設計を選ぶ**という、次元の違う解決策です。
389412

390-
```
413+
![image](https://raw.githubusercontent.com/ken-okabe/web-images5/main/img_1745716642404.png)
391414

392-
もはやそこには中間的な`timelineB``timelineC`も存在せず、菱形(ダイアモンド)構造自体が生まれません。したがって、グリッチや複数回更新という問題は**構造的に発生し得ない**のです。これは、発生した問題を後から解決するのではなく、**問題が発生しない優れた設計を選ぶ**という、次元の違う解決策です。
393415

394416
#### 2\. 実行効率
395417

astro.config.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import starlightSidebarTopics from 'starlight-sidebar-topics';
99
// Import MathJax plugins
1010
import remarkMath from 'remark-math';
1111
import rehypeMathjax from 'rehype-mathjax';
12-
13-
import d2 from 'astro-d2';
12+
1413

1514
export default defineConfig({
1615
// GitHub Pages configuration
@@ -37,7 +36,7 @@ export default defineConfig({
3736
}
3837
),
3938
],
40-
}), d2()],
39+
})],
4140
// Global Markdown configuration for Astro
4241
markdown: {
4342
remarkPlugins: [remarkMath],

package-lock.json

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"@astrojs/starlight": "^0.34.3",
1515
"@terrastruct/d2": "^0.1.23",
1616
"astro": "^5.6.1",
17-
"astro-d2": "^0.8.0",
1817
"fs-extra": "^11.3.0",
1918
"gray-matter": "^4.0.3",
2019
"mdast-util-to-string": "^4.0.0",

src/content/docs/en/book/unit-5/section-3/1-map.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const numbers = Timeline(5);
2525
// Pass a function: (x: number) => string
2626
const labels = numbers.map(x => `Score: ${x}`);
2727

28-
console.log(labels.at(Now)); // "Score: 5"
28+
console.log(labels.at(Now)); // "Score: 5"share
2929

3030
// When the source is updated, labels is automatically updated as well
3131
numbers.define(Now, 100);
@@ -38,19 +38,7 @@ When you call `map`, a **Dependency** is registered internally between the two `
3838

3939
The dependency created by `map` is **Static**. Once you define the relationship `labels = numbers.map(...)`, the rule itself—the transformation of the value—does not change later.
4040

41-
```d2
42-
Documentation -> Website: Starlight
43-
```
44-
45-
```txt
46-
+-----------------+ .map(x => `Score: ${x}`) +-----------------+
47-
| numbers | --------------------------------> | labels |
48-
| (Timeline<number>) | | (Timeline<string>) |
49-
+-----------------+ +-----------------+
50-
^ |
51-
| .define(Now, 100) V
52-
+------------- Value propagates to "Score: 100"
53-
```
41+
![image](https://raw.githubusercontent.com/ken-okabe/web-images5/main/img_1752494846714.png)
5442

5543
This simple concept of a "static dependency" is the foundation for understanding the "dynamic" dependencies constructed by `bind` and `using`, which will be introduced later.
5644

src/content/docs/en/book/unit-5/section-3/3-bind.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,25 @@ The benefits of this `bind` approach are numerous.
123123

124124
As a common approach, trying to define `B` and `C` separately with `.map` and then combining them to create `D` gives rise to the "problematic structure" of a diamond. However, by using `bind`, the dependency graph changes fundamentally.
125125

126-
Plaintext
127126

128-
```
129-
+-----------+ .bind(a => { return Timeline(d); }) +-----------+
130-
| Timeline A| ------------------------------------------> | Timeline D|
131-
+-----------+ +-----------+
132-
```
127+
![image](https://raw.githubusercontent.com/ken-okabe/web-images5/main/img_1752493931653.png)
133128

134129
There are no longer intermediate `timelineB` or `timelineC`, and the diamond structure itself is never formed. Therefore, problems like glitches and multiple updates **cannot structurally occur**. This is a solution on a different level: not fixing a problem after it occurs, but **choosing a superior design where the problem does not arise**.
135130

131+
![image](https://raw.githubusercontent.com/ken-okabe/web-images5/main/img_1745716642404.png)
132+
133+
134+
#### 2. Execution Efficiency
135+
136+
In this structure, every time `A` is updated, the function passed to `bind` is executed only once, and `D` is calculated only once. This is highly efficient.
137+
138+
#### 3. Complete Elimination of Transactional Processing
139+
140+
Even more importantly, the **complex
141+
136142
#### 2. Execution Efficiency
137143

138-
In this structure, every time `A` is updated, the function passed to `bind` is executed only once, and `D` is calculated only once. This is highly efficient.
144+
In this structure, every time `A` is updated, the function passed to `bind` is executed only once, and `D` is calculated only once. This is highly efficient.
139145

140146
#### 3. Complete Elimination of Transactional Processing
141147

src/content/docs/ja/book/unit-5/section-3/1-map.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ console.log(labels.at(Now)); // "Score: 5"
2828
// ソースを更新すると、labelsも自動的に更新される
2929
numbers.define(Now, 100);
3030
console.log(labels.at(Now)); // "Score: 100"
31+
```txt```txt
32+
+-----------------+ .map(x => `Score: ${x}`) +-----------------+
33+
| numbers | --------------------------------> | labels |
34+
| (Timeline<number>) | | (Timeline<string>) |
35+
+-----------------+ +-----------------+
36+
^ |
37+
| .define(Now, 100) V
38+
+------------- 値が"Score: 100"へ伝播
3139

3240
```
33-
34-
## 依存グラフ (Dependency Graph)
35-
36-
`map`を呼び出すと、内部では2つの`Timeline`の間に**依存関係 (Dependency)** が登録されます。この関係性のネットワーク全体を**依存グラフ**と呼びます。
37-
38-
`map`が作る依存関係は**静的 (Static)** です。一度`labels = numbers.map(...)`という関係を定義したら、`numbers``labels`の間の「値を変換する」というルールそのものが後から変わることはありません。
39-
40-
```txt
4141
+-----------------+ .map(x => `Score: ${x}`) +-----------------+
4242
| numbers | --------------------------------> | labels |
4343
| (Timeline<number>) | | (Timeline<string>) |
@@ -47,6 +47,16 @@ console.log(labels.at(Now)); // "Score: 100"
4747
+------------- 値が"Score: 100"へ伝播
4848

4949
```
50+
```
51+
52+
## 依存グラフ (Dependency Graph)
53+
54+
`map`を呼び出すと、内部では2つの`Timeline`の間に**依存関係 (Dependency)** が登録されます。この関係性のネットワーク全体を**依存グラフ**と呼びます。
55+
56+
`map`が作る依存関係は**静的 (Static)** です。一度`labels = numbers.map(...)`という関係を定義したら、`numbers``labels`の間の「値を変換する」というルールそのものが後から変わることはありません。
57+
58+
![image](https://raw.githubusercontent.com/ken-okabe/web-images5/main/img_1752494846714.png)
59+
5060

5161
このシンプルな「静的な依存関係」の概念が、後に出てくる`bind``using`が構築する「動的な」依存関係を理解するための基礎となります。
5262

0 commit comments

Comments
 (0)