Skip to content

Commit 56d6bc0

Browse files
committed
Update the build to generate gh pages
1 parent 18addce commit 56d6bc0

File tree

8 files changed

+32
-162
lines changed

8 files changed

+32
-162
lines changed

.github/workflows/ci.yml

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
name: CI
2-
on:
3-
push:
4-
tags: ["*"]
5-
branches: ['**', '!update/**', '!pr/**']
6-
pull_request:
7-
branches: ['**', '!update/**', '!pr/**']
2+
on: [push, pull_request]
83
jobs:
9-
docs:
10-
name: Build docs
4+
tests:
5+
name: Run tests
116
runs-on: ubuntu-latest
127
steps:
138
- uses: actions/checkout@v4
@@ -16,9 +11,11 @@ jobs:
1611
distribution: 'temurin'
1712
java-version: '17'
1813
- uses: coursier/cache-action@v6
19-
- run: sbt docs/run
20-
tests:
21-
name: Run tests
14+
- name: Run tests
15+
run: |
16+
sbt "+Test/compile; +test"
17+
docs:
18+
name: Build docs
2219
runs-on: ubuntu-latest
2320
steps:
2421
- uses: actions/checkout@v4
@@ -27,6 +24,4 @@ jobs:
2724
distribution: 'temurin'
2825
java-version: '17'
2926
- uses: coursier/cache-action@v6
30-
- name: Run tests
31-
run: |
32-
sbt "+Test/compile; +test"
27+
- run: sbt docs/run

.github/workflows/docs.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: docs
2+
on: [push]
3+
jobs:
4+
docs:
5+
name: Build docs
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v4
9+
- uses: actions/setup-java@v4
10+
with:
11+
distribution: 'temurin'
12+
java-version: '17'
13+
- uses: coursier/cache-action@v6
14+
- run: sbt docs/run
15+
- uses: peaceiris/actions-gh-pages@v4
16+
with:
17+
github_token: ${{ secrets.GITHUB_TOKEN }}
18+
enable_jekyll: true
19+
publish_dir: ./docs-gen/target/mdoc/.

README.md

+1-145
Original file line numberDiff line numberDiff line change
@@ -5,148 +5,4 @@ This implementation is inspired by
55
[the original paper by Huet](https://www.st.cs.uni-saarland.de/edu/seminare/2005/advanced-fp/docs/huet-zipper.pdf),
66
as well as the [Argonaut’s JSON Zipper](http://argonaut.io/doc/zipper/).
77

8-
Consider the following example:
9-
10-
```scala
11-
// Define a tree data structure
12-
case class Tree(x: Int, c: List[Tree] = List.empty)
13-
14-
// Create a tree
15-
val tree = Tree(
16-
1, List(
17-
Tree(
18-
11, List(
19-
Tree(111),
20-
Tree(112)
21-
)
22-
),
23-
Tree(
24-
12, List(
25-
Tree(121),
26-
Tree(
27-
122, List(
28-
Tree(1221),
29-
Tree(1222)
30-
)
31-
),
32-
Tree(123)
33-
)
34-
),
35-
Tree(13)
36-
)
37-
)
38-
```
39-
40-
<img src="./docs/images/readme/tree.png" height="500px" />
41-
42-
Since the tree is immutable, modifying it can be a pain,
43-
but it’s easily solved with a Zipper:
44-
45-
```scala
46-
import zipper._
47-
48-
// Use a Zipper to move around and change data
49-
val modified = {
50-
Zipper(tree)
51-
.moveDownAt(1) // 12
52-
.moveDownRight // 123
53-
.deleteAndMoveLeft // 122
54-
.moveDownLeft // 1221
55-
.update(_.copy(x = -1))
56-
.moveRight // 1222
57-
.set(Tree(-2))
58-
.moveUp // 122
59-
.moveUp // 12
60-
.rewindLeft // 11
61-
.moveDownRight // 112
62-
.moveLeftBy(1) // 111
63-
.deleteAndMoveUp // 11
64-
.commit // commit the changes and return the result
65-
}
66-
```
67-
68-
Here’s what the modified tree looks like:
69-
70-
<img src="./docs/images/readme/modified.png" height="500px" />
71-
72-
If we draw both trees side by side, we’ll see that
73-
the unchanged parts are shared:
74-
75-
<img src="./docs/images/readme/both.png" height="500px" />
76-
77-
### Usage
78-
79-
Include these lines in your `build.sbt`:
80-
81-
```scala
82-
// for JVM
83-
libraryDependencies += "io.github.stanch" %% "zipper" % "0.5.2"
84-
85-
// for Scala.js
86-
libraryDependencies += "io.github.stanch" %%% "zipper" % "0.5.2"
87-
```
88-
89-
#### Unzip
90-
91-
In order for the Zipper to work on your data structure `Tree`, you need an implicit instance of `Unzip[Tree]`.
92-
`Unzip` is defined as follows:
93-
94-
```scala
95-
trait Unzip[A] {
96-
def unzip(node: A): List[A]
97-
def zip(node: A, children: List[A]): A
98-
}
99-
```
100-
101-
As we saw before, the library can automatically derive `Unzip[Tree]`
102-
if the `Tree` is a case class that has a single field of type `List[Tree]`.
103-
It is also possible to derive an `Unzip[Tree]` for similar cases, but with other collections:
104-
105-
```scala
106-
scala> case class Tree(x: Int, c: Vector[Tree] = Vector.empty)
107-
defined class Tree
108-
109-
scala> implicit val unzip = Unzip.For[Tree, Vector].derive
110-
unzip: zipper.Unzip[Tree] = zipper.GenericUnzipInstances$For$$anon$2@6389ff1a
111-
```
112-
113-
The automatic derivation is powered by [shapeless](https://github.com/milessabin/shapeless).
114-
115-
#### Moves, failures and recovery
116-
117-
There are many operations defined on a `Zipper`.
118-
Some of them are not safe, e.g. `moveLeft` will fail with an exception
119-
if there are no elements on the left.
120-
For all unsafe operations a safe version is provided, which is prefixed with `try`.
121-
These operations return a `Zipper.MoveResult`, which allows to recover from the failure or return to the original state:
122-
123-
```scala
124-
scala> val tree = Tree(1, Vector(Tree(3), Tree(4)))
125-
tree: Tree = Tree(1,Vector(Tree(3,Vector()), Tree(4,Vector())))
126-
127-
scala> val modified = {
128-
| Zipper(tree)
129-
| .moveDownLeft
130-
| .tryMoveLeft.getOrElse(_.insertLeft(Tree(2)).moveLeft)
131-
| .commit
132-
| }
133-
modified: Tree = Tree(1,Vector(Tree(2,Vector()), Tree(3,Vector()), Tree(4,Vector())))
134-
```
135-
136-
#### Loops
137-
138-
`Zipper` provides a looping functionality, which can be useful with recursive data:
139-
140-
```scala
141-
scala> val tree = Tree(1, Vector(Tree(2), Tree(3), Tree(5)))
142-
tree: Tree = Tree(1,Vector(Tree(2,Vector()), Tree(3,Vector()), Tree(5,Vector())))
143-
144-
scala> val modified = {
145-
| Zipper(tree)
146-
| .moveDownLeft
147-
| .repeatWhile(_.x < 5, _.tryMoveRight)
148-
| .insertRight(Tree(4))
149-
| .commit
150-
| }
151-
modified: Tree = Tree(1,Vector(Tree(2,Vector()), Tree(3,Vector()), Tree(5,Vector()), Tree(4,Vector())))
152-
```
8+
See https://stanch.github.io/zipper for more details.

_config.yml docs/_config.yml

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

docs/user-guide/README.md docs/index.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ val tree = Tree(
3737
)
3838
```
3939

40-
<img src="/docs/images/readme/tree.png" height="500px" />
40+
<img src="images/tree.png" height="500px" />
4141

4242
Since the tree is immutable, modifying it can be a pain,
4343
but it’s easily solved with a Zipper:
@@ -67,12 +67,12 @@ val modified = {
6767

6868
Here’s what the modified tree looks like:
6969

70-
<img src="/docs/images/readme/modified.png" height="500px" />
70+
<img src="images/modified.png" height="500px" />
7171

7272
If we draw both trees side by side, we’ll see that
7373
the unchanged parts are shared:
7474

75-
<img src="/docs/images/readme/both.png" height="500px" />
75+
<img src="images/both.png" height="500px" />
7676

7777
### Usage
7878

0 commit comments

Comments
 (0)