Skip to content

Commit

Permalink
📚 docs(README): Move "Add values" before "Slice".
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Nov 28, 2020
1 parent f4c7f90 commit 6c89ec7
Showing 1 changed file with 38 additions and 31 deletions.
69 changes: 38 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ Parent is [@aureooms/js-persistent](https://github.com/aureooms/js-persistent).
* [:question: Predicates](#question-predicates)
* [`Tree#measure() -> m`](#treemeasure---m)
* [`Tree#empty() -> Boolean`](#treeempty---boolean)
* [:pizza: Slice](#pizza-slice)
* [`Tree#head() -> x`](#treehead---x)
* [`Tree#last() -> x`](#treelast---x)
* [`Tree#init() -> Tree`](#treeinit---tree)
* [`Tree#tail() -> Tree`](#treetail---tree)
* [:salt: Add values](#salt-add-values)
* [`Tree#push(x) -> Tree`](#treepushx---tree)
* [`Tree#cons(x) -> Tree`](#treeconsx---tree)
* [`Tree#append(Iterable) -> Tree`](#treeappenditerable---tree)
* [`Tree#prepend(Iterable) -> Tree`](#treeprependiterable---tree)
* [:pizza: Slice](#pizza-slice)
* [`Tree#head() -> x`](#treehead---x)
* [`Tree#last() -> x`](#treelast---x)
* [`Tree#init() -> Tree`](#treeinit---tree)
* [`Tree#tail() -> Tree`](#treetail---tree)
* [:last_quarter_moon: Merge](#last_quarter_moon-merge)
* [`Tree#concat(Tree) -> Tree`](#treeconcattree---tree)
* [:broken_heart: Split](#broken_heart-split)
Expand All @@ -75,12 +75,14 @@ All methods are pure functions that do not modify their object.
> The [parent project](https://github.com/aureooms/js-persistent) shows how
> specialized persistent data structures can be build on top of those methods.

### :cactus: Definition of a `Tree`

data Tree x = Empty
| Single x
| Deep ( Digit x ) ( Tree ( Node x ) ) ( Digit x )


### :straight_ruler: Definition of a `Measure`

Measure = (
Expand Down Expand Up @@ -129,6 +131,7 @@ const { from , empty } = require( '@aureooms/js-fingertree' ) ;
import { from , empty } from '@aureooms/js-fingertree' ;
```


### :baby: How to create a `Tree`

#### `empty(Measure) -> Tree`
Expand All @@ -147,6 +150,7 @@ Create a tree from a measure object and an iterable.
let tree = from( counter , 'abc' ) ;
```


### :question: Predicates

#### `Tree#measure() -> m`
Expand All @@ -165,74 +169,77 @@ Returns `true` if the tree is empty, `false` otherwise.
return tree.empty() ? 'empty' : 'not empty' ;
```

### :pizza: Slice

#### `Tree#head() -> x`
### :salt: Add values

Returns the left-most value in the tree.
#### `Tree#push(x) -> Tree`

Returns a new tree with an additional value as the new right-most value.

```js
let head = tree.head() ; // 'a'
tree = tree.cons('k');
```

#### `Tree#last() -> x`
#### `Tree#cons(x) -> Tree`

Returns the right-most value in the tree.
Returns a new tree with an additional value as the new left-most value.

```js
let last = tree.last() ; // 'b'
tree = tree.cons('g');
```

#### `Tree#init() -> Tree`
#### `Tree#append(Iterable) -> Tree`

Returns a new tree without the right-most value.
Equivalent to applying `push` to each value of the iterable in order.

```js
while ( ! tree.empty() ) tree = tree.init() ;
tree.append( 'www' ) ;
```

#### `Tree#tail() -> Tree`
#### `Tree#prepend(Iterable) -> Tree`

Returns a new tree without the left-most value.
Equivalent to applying `cons` to each value of the iterable in reverse order.

```js
while ( ! tree.empty() ) tree = tree.tail() ;
tree.prepend( 'xyz' ) ;
```

### :salt: Add values

#### `Tree#push(x) -> Tree`
### :pizza: Slice

Returns a new tree with an additional value as the new right-most value.
#### `Tree#head() -> x`

Returns the left-most value in the tree.

```js
tree = tree.cons('k');
let head = tree.head() ; // 'a'
```

#### `Tree#cons(x) -> Tree`
#### `Tree#last() -> x`

Returns a new tree with an additional value as the new left-most value.
Returns the right-most value in the tree.

```js
tree = tree.cons('g');
let last = tree.last() ; // 'b'
```

#### `Tree#append(Iterable) -> Tree`
#### `Tree#init() -> Tree`

Equivalent to applying `push` to each value of the iterable in order.
Returns a new tree without the right-most value.

```js
tree.append( 'www' ) ;
while ( ! tree.empty() ) tree = tree.init() ;
```

#### `Tree#prepend(Iterable) -> Tree`
#### `Tree#tail() -> Tree`

Equivalent to applying `cons` to each value of the iterable in reverse order.
Returns a new tree without the left-most value.

```js
tree.prepend( 'xyz' ) ;
while ( ! tree.empty() ) tree = tree.tail() ;
```


### :last_quarter_moon: Merge

#### `Tree#concat(Tree) -> Tree`
Expand Down

0 comments on commit 6c89ec7

Please sign in to comment.