@@ -42,16 +42,16 @@ Parent is [@aureooms/js-persistent](https://github.com/aureooms/js-persistent).
42
42
* [ :question : Predicates] ( #question-predicates )
43
43
* [ ` Tree#measure() -> m ` ] ( #treemeasure---m )
44
44
* [ ` Tree#empty() -> Boolean ` ] ( #treeempty---boolean )
45
- * [ :pizza : Slice] ( #pizza-slice )
46
- * [ ` Tree#head() -> x ` ] ( #treehead---x )
47
- * [ ` Tree#last() -> x ` ] ( #treelast---x )
48
- * [ ` Tree#init() -> Tree ` ] ( #treeinit---tree )
49
- * [ ` Tree#tail() -> Tree ` ] ( #treetail---tree )
50
45
* [ :salt : Add values] ( #salt-add-values )
51
46
* [ ` Tree#push(x) -> Tree ` ] ( #treepushx---tree )
52
47
* [ ` Tree#cons(x) -> Tree ` ] ( #treeconsx---tree )
53
48
* [ ` Tree#append(Iterable) -> Tree ` ] ( #treeappenditerable---tree )
54
49
* [ ` Tree#prepend(Iterable) -> Tree ` ] ( #treeprependiterable---tree )
50
+ * [ :pizza : Slice] ( #pizza-slice )
51
+ * [ ` Tree#head() -> x ` ] ( #treehead---x )
52
+ * [ ` Tree#last() -> x ` ] ( #treelast---x )
53
+ * [ ` Tree#init() -> Tree ` ] ( #treeinit---tree )
54
+ * [ ` Tree#tail() -> Tree ` ] ( #treetail---tree )
55
55
* [ :last_quarter_moon : Merge] ( #last_quarter_moon-merge )
56
56
* [ ` Tree#concat(Tree) -> Tree ` ] ( #treeconcattree---tree )
57
57
* [ :broken_heart : Split] ( #broken_heart-split )
@@ -75,12 +75,14 @@ All methods are pure functions that do not modify their object.
75
75
> The [ parent project] ( https://github.com/aureooms/js-persistent ) shows how
76
76
> specialized persistent data structures can be build on top of those methods.
77
77
78
+
78
79
### :cactus : Definition of a ` Tree `
79
80
80
81
data Tree x = Empty
81
82
| Single x
82
83
| Deep ( Digit x ) ( Tree ( Node x ) ) ( Digit x )
83
84
85
+
84
86
### :straight_ruler : Definition of a ` Measure `
85
87
86
88
Measure = (
@@ -129,6 +131,7 @@ const { from , empty } = require( '@aureooms/js-fingertree' ) ;
129
131
import { from , empty } from ' @aureooms/js-fingertree' ;
130
132
```
131
133
134
+
132
135
### :baby : How to create a ` Tree `
133
136
134
137
#### ` empty(Measure) -> Tree `
@@ -147,6 +150,7 @@ Create a tree from a measure object and an iterable.
147
150
let tree = from ( counter , ' abc' ) ;
148
151
```
149
152
153
+
150
154
### :question : Predicates
151
155
152
156
#### ` Tree#measure() -> m `
@@ -165,74 +169,77 @@ Returns `true` if the tree is empty, `false` otherwise.
165
169
return tree .empty () ? ' empty' : ' not empty' ;
166
170
```
167
171
168
- ### :pizza : Slice
169
172
170
- #### ` Tree#head() -> x `
173
+ ### : salt : Add values
171
174
172
- Returns the left-most value in the tree.
175
+ #### ` Tree#push(x) -> Tree `
176
+
177
+ Returns a new tree with an additional value as the new right-most value.
173
178
174
179
``` js
175
- let head = tree .head () ; // 'a'
180
+ tree = tree .cons ( ' k ' );
176
181
```
177
182
178
- #### ` Tree#last( ) -> x `
183
+ #### ` Tree#cons(x ) -> Tree `
179
184
180
- Returns the right-most value in the tree .
185
+ Returns a new tree with an additional value as the new left-most value .
181
186
182
187
``` js
183
- let last = tree .last () ; // 'b'
188
+ tree = tree .cons ( ' g ' );
184
189
```
185
190
186
- #### ` Tree#init( ) -> Tree `
191
+ #### ` Tree#append(Iterable ) -> Tree `
187
192
188
- Returns a new tree without the right-most value .
193
+ Equivalent to applying ` push ` to each value of the iterable in order .
189
194
190
195
``` js
191
- while ( ! tree .empty () ) tree = tree . init ( ) ;
196
+ tree .append ( ' www ' ) ;
192
197
```
193
198
194
- #### ` Tree#tail( ) -> Tree `
199
+ #### ` Tree#prepend(Iterable ) -> Tree `
195
200
196
- Returns a new tree without the left-most value .
201
+ Equivalent to applying ` cons ` to each value of the iterable in reverse order .
197
202
198
203
``` js
199
- while ( ! tree .empty () ) tree = tree . tail ( ) ;
204
+ tree .prepend ( ' xyz ' ) ;
200
205
```
201
206
202
- ### :salt : Add values
203
207
204
- #### ` Tree#push(x) -> Tree `
208
+ ### : pizza : Slice
205
209
206
- Returns a new tree with an additional value as the new right-most value.
210
+ #### ` Tree#head() -> x `
211
+
212
+ Returns the left-most value in the tree.
207
213
208
214
``` js
209
- tree = tree .cons ( ' k ' );
215
+ let head = tree .head () ; // 'a'
210
216
```
211
217
212
- #### ` Tree#cons(x ) -> Tree `
218
+ #### ` Tree#last( ) -> x `
213
219
214
- Returns a new tree with an additional value as the new left-most value .
220
+ Returns the right-most value in the tree .
215
221
216
222
``` js
217
- tree = tree .cons ( ' g ' );
223
+ let last = tree .last () ; // 'b'
218
224
```
219
225
220
- #### ` Tree#append(Iterable ) -> Tree `
226
+ #### ` Tree#init( ) -> Tree `
221
227
222
- Equivalent to applying ` push ` to each value of the iterable in order .
228
+ Returns a new tree without the right-most value .
223
229
224
230
``` js
225
- tree .append ( ' www ' ) ;
231
+ while ( ! tree .empty () ) tree = tree . init ( ) ;
226
232
```
227
233
228
- #### ` Tree#prepend(Iterable ) -> Tree `
234
+ #### ` Tree#tail( ) -> Tree `
229
235
230
- Equivalent to applying ` cons ` to each value of the iterable in reverse order .
236
+ Returns a new tree without the left-most value .
231
237
232
238
``` js
233
- tree .prepend ( ' xyz ' ) ;
239
+ while ( ! tree .empty () ) tree = tree . tail ( ) ;
234
240
```
235
241
242
+
236
243
### :last_quarter_moon : Merge
237
244
238
245
#### ` Tree#concat(Tree) -> Tree `
0 commit comments