You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/manual.md
+10-17Lines changed: 10 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,8 @@ Manual
4
4
This package defines julia implementations for the common types `Option` (aka `Maybe`), `Either` and `Try`, as well as
5
5
one extra type `ContextManager` which mimics Python's `with`-ContextManager.
6
6
7
-
Unlike typical implementations of `Option`, and `Either` which define them as new separate type-hierarchies, in
8
-
`DataTypesBasic` both actually share a common part: `Identity`.
7
+
Unlike typical implementations of `Option`, and `Either` which define them as new separate
8
+
type-hierarchies, in `DataTypesBasic` both actually share a common parts: `Identity` and `Const`.
9
9
10
10
11
11
Identity
@@ -32,19 +32,12 @@ Think of `Identity` as lifting a value into the world of containers. `DataTypesB
32
32
an `Identity` container to a `Vector` or else. This will come in handy soon. For now it is important to understand
33
33
that wrapping some value `42` into `Identity(42)` makes it interactable on a container-level.
34
34
35
-
Nothing
36
-
-------
37
-
38
-
`DataTypesBasic` makes heavy use of the builtin `Base.Nothing`. In the context here, `nothing` is interpreted as an
39
-
empty container, something without any element. Or from another perspective: `nothing` works like a short-cycling abort.
40
-
41
35
42
36
Const
43
37
-----
44
38
45
-
`Const` looks like `Identity`, but behaves like `Nothing`. Its name suggests that whatever is in it will stay
46
-
**const**ant. It behaves like an empty container, and can also be seen as aborting a program. Compared to `Nothing`,
47
-
the `Const` container not only aborts, but further returns some useful abort-info.
39
+
`Const` looks like `Identity`, but behaves like an empty container. Its name suggests that whatever is in it will stay
40
+
**const**ant. Alternatively, it can also be interpreted as aborting a program. Use `Const(nothing)` to represent an empty Container. `Const(...)` is in this sense an empty container with additional information.
48
41
49
42
```julia
50
43
struct Identity{T}
@@ -73,17 +66,17 @@ julia> for i in Identity("hello")
73
66
Option
74
67
-------
75
68
76
-
Option is a container which has either 1 value or 0. Having `Identity` and `Nothing` already at hand, it is defined as
69
+
Option is a container which has either 1 value or 0. Having `Identity` and `Const{Nothing}` already at hand, it is defined as
77
70
```julia
78
-
Option{T} = Union{Identity{T}, Nothing}
71
+
Option{T} = Union{Identity{T}, Const{Nothing}}
79
72
```
80
73
81
74
Use it like
82
75
```julia
83
76
using DataTypesBasic
84
77
85
78
fo(a::Identity{String}) = a.value *"!"
86
-
fo(a::Nothing) ="fallback behaviour"
79
+
fo(a::Const{Nothing}) ="fallback behaviour"
87
80
88
81
fo(Option("hi")) # "hi!"
89
82
fo(Option(nothing)) # "fallback behaviour"
@@ -101,7 +94,7 @@ Here an example for such a higher level perspective
101
94
using DataTypesBasic
102
95
103
96
flatten(a::Identity) = a.value
104
-
flatten(a::Nothing) = a
97
+
flatten(a::Const) = a
105
98
106
99
# map a function over 2 Options, getting an option back
107
100
functionmap2(f, a::Option{S}, b::Option{T}) where {S, T}
@@ -119,7 +112,7 @@ end # Identity("hi there")
119
112
120
113
map2(Option(1), Option()) do a, b
121
114
a + b
122
-
end# nothing
115
+
end#Const(nothing)
123
116
```
124
117
125
118
The package `TypeClasses.jl` (soon to come) implements a couple of such higher level concepts of immense use
@@ -180,7 +173,7 @@ For further details, don't hesitate to consult the source code `src/Either.jl` o
180
173
Try
181
174
----
182
175
183
-
`Try` is a special case of `Either`, where `Const` can only bear Exceptions.
176
+
`Try` is another special case of `Either`, where `Const` can only bear Exceptions.
0 commit comments