Skip to content

Commit ac290e3

Browse files
author
Stephan Sahm
committed
adapted README and Doc respectively
still many things to document maybe also better to structure by type, i.e. create a page for Identity, for Option, for Either, and so forth.
1 parent bbae7db commit ac290e3

5 files changed

Lines changed: 112 additions & 86 deletions

File tree

README.md

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,83 +7,4 @@
77

88
This package defines julia implementations for the common types `Option` (aka `Maybe`), `Either` and `Try`, as well as one extra type `ContextManager` which mimics Python's `with`-ContextManager.
99

10-
Use it like
11-
```julia
12-
using DataTypesBasic
13-
```
14-
15-
## Installation
16-
17-
```julia
18-
using Pkg
19-
pkg"registry add https://github.com/JuliaRegistries/General" # central julia repository
20-
pkg"registry add https://github.com/schlichtanders/SchlichtandersJuliaRegistry.jl" # custom repository
21-
pkg"add DataTypesBasic"
22-
```
23-
24-
## Option
25-
26-
`Option{T} = Union{Identity{T}, Nothing}`
27-
28-
Use it like
29-
```julia
30-
using DataTypesBasic
31-
32-
fo(a::Identity{String}) = a.value * "!"
33-
fo(a::Nothing) = "fallback behaviour"
34-
35-
fo(Option("hi")) # "hi!"
36-
fo(Option(nothing)) # "fallback behaviour"
37-
fo(Option()) # "fallback behaviour"
38-
```
39-
40-
The real power of `Option` comes from generic functionalities which you can define on it. `DataTypesBasic` already defines the following:
41-
`Base.iterate`, `Base.foreach`, `Base.map`, `Base.get`, `DataTypesBasic.iftrue`, `DataTypesBasic.iffalse`, `Base.isnothing`, `DataTypesBasic.issomething`. Please
42-
consult the respective function definition for details.
43-
44-
Here an example for such a higher level perspective
45-
```julia
46-
using DataTypesBasic
47-
48-
flatten(a::Identity) = a.value
49-
flatten(a::Nothing) = a
50-
51-
function map2(f, a::Option{S}, b::Option{T}) where {S, T} # this comes
52-
nested_option = map(a) do a′
53-
map(b) do b′
54-
f(a′, b′)
55-
end
56-
end
57-
flatten(nested_option)
58-
end
59-
60-
map2(Option("hi"), Option("there")) do a, b
61-
"$a $b"
62-
end # Identity("hi there")
63-
64-
map2(Option(1), Option()) do a, b
65-
a + b
66-
end # nothing
67-
```
68-
69-
The package `TypeClasses.jl` (soon to come) implements a couple of such higher level concepts of immense use
70-
(like Functors, Applicatives and Monads).
71-
72-
73-
## [TODO] Try
74-
75-
Please see the tests `test/Try.jl`.
76-
77-
## [TODO] Either
78-
79-
Please see the tests `test/Either.jl`.
80-
81-
## [TODO] ContextManager
82-
83-
Please see the tests `test/ContextManager.jl`.
84-
85-
## [TODO] Other
86-
87-
For abstraction purposes, there is also `Const` and `Identity` defined.
88-
89-
Please see the tests `test/Const.jl` and `test/Identity.jl` respectively.
10+
For more details check out the [documentation](https://schlichtanders.github.io/DataTypesBasic.jl/dev/).

docs/make.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ makedocs(;
1313
),
1414
pages=[
1515
"Home" => "index.md",
16+
"Manual" => "manual.md",
17+
"Library" => "library.md",
1618
],
1719
)
1820

docs/src/index.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
1-
```@meta
2-
CurrentModule = DataTypesBasic
1+
# DataTypesBasic.jl
2+
3+
This package defines julia implementations for the common types `Option` (aka `Maybe`), `Either` and `Try`, as well as one extra type `ContextManager` which mimics Python's `with`-ContextManager.
4+
5+
6+
## Installation
7+
8+
```julia
9+
using Pkg
10+
pkg"registry add https://github.com/JuliaRegistries/General" # central julia repository
11+
pkg"registry add https://github.com/schlichtanders/SchlichtandersJuliaRegistry.jl" # custom repository
12+
pkg"add DataTypesBasic"
13+
```
14+
15+
Use it like
16+
```julia
17+
using DataTypesBasic
318
```
419

5-
# DataTypesBasic
620

7-
```@index
21+
## Manual Outline
22+
23+
```@contents
24+
Pages = ["manual.md"]
825
```
926

10-
```@autodocs
11-
Modules = [DataTypesBasic]
27+
## [Library Index](@id main-index)
28+
29+
```@index
30+
Pages = ["library.md"]
1231
```

docs/src/library.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```@meta
2+
CurrentModule = DataTypesBasic
3+
```
4+
5+
# Public API
6+
7+
```@index
8+
```
9+
10+
```@autodocs
11+
Modules = [DataTypesBasic]
12+
```

docs/src/manual.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Manual
2+
======
3+
4+
This package defines julia implementations for the common types `Option` (aka `Maybe`), `Either` and `Try`, as well as one extra type `ContextManager` which mimics Python's `with`-ContextManager.
5+
6+
7+
## Option
8+
9+
`Option{T} = Union{Identity{T}, Nothing}`
10+
11+
Use it like
12+
```julia
13+
using DataTypesBasic
14+
15+
fo(a::Identity{String}) = a.value * "!"
16+
fo(a::Nothing) = "fallback behaviour"
17+
18+
fo(Option("hi")) # "hi!"
19+
fo(Option(nothing)) # "fallback behaviour"
20+
fo(Option()) # "fallback behaviour"
21+
```
22+
23+
The real power of `Option` comes from generic functionalities which you can define on it. `DataTypesBasic` already defines the following:
24+
`Base.iterate`, `Base.foreach`, `Base.map`, `Base.get`, `DataTypesBasic.iftrue`, `DataTypesBasic.iffalse`, `Base.isnothing`, `DataTypesBasic.issomething`. Please
25+
consult the respective function definition for details.
26+
27+
Here an example for such a higher level perspective
28+
```julia
29+
using DataTypesBasic
30+
31+
flatten(a::Identity) = a.value
32+
flatten(a::Nothing) = a
33+
34+
function map2(f, a::Option{S}, b::Option{T}) where {S, T} # this comes
35+
nested_option = map(a) do a′
36+
map(b) do b′
37+
f(a′, b′)
38+
end
39+
end
40+
flatten(nested_option)
41+
end
42+
43+
map2(Option("hi"), Option("there")) do a, b
44+
"$a $b"
45+
end # Identity("hi there")
46+
47+
map2(Option(1), Option()) do a, b
48+
a + b
49+
end # nothing
50+
```
51+
52+
The package `TypeClasses.jl` (soon to come) implements a couple of such higher level concepts of immense use
53+
(like Functors, Applicatives and Monads).
54+
55+
56+
## [TODO] Try
57+
58+
Please see the tests `test/Try.jl`.
59+
60+
## [TODO] Either
61+
62+
Please see the tests `test/Either.jl`.
63+
64+
## [TODO] ContextManager
65+
66+
Please see the tests `test/ContextManager.jl`.
67+
68+
## [TODO] Other
69+
70+
For abstraction purposes, there is also `Const` and `Identity` defined.
71+
72+
Please see the tests `test/Const.jl` and `test/Identity.jl` respectively.

0 commit comments

Comments
 (0)