Skip to content

Commit c9e6322

Browse files
Stephan SahmStephan Sahm
authored andcommitted
adapted doc
1 parent fcc1fe4 commit c9e6322

3 files changed

Lines changed: 14 additions & 18 deletions

File tree

Changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- `@either` macro with which you can construct `Either` using ? operator or if-else.
1818

1919
### Changed
20-
- Option and Either are now represented as `Union` of Identity, Nothing and Const respectively
20+
- Option is now represented as Union of Identity and Const{Nothing}
21+
- Either is now represented as `Union` of Identity and Const
22+
- Try is now represented as `Union` of Identity and Const{<:Exception}
2123
- flatten in general is now unified to use `convert` for interoperability between similar
2224
container types
2325
- flatten of ContextManager is again reverted back to not use `FlattenMe` anymore. Instead the

docs/src/manual.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Manual
44
This package defines julia implementations for the common types `Option` (aka `Maybe`), `Either` and `Try`, as well as
55
one extra type `ContextManager` which mimics Python's `with`-ContextManager.
66

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`.
99

1010

1111
Identity
@@ -32,19 +32,12 @@ Think of `Identity` as lifting a value into the world of containers. `DataTypesB
3232
an `Identity` container to a `Vector` or else. This will come in handy soon. For now it is important to understand
3333
that wrapping some value `42` into `Identity(42)` makes it interactable on a container-level.
3434

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-
4135

4236
Const
4337
-----
4438

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.
4841

4942
```julia
5043
struct Identity{T}
@@ -73,17 +66,17 @@ julia> for i in Identity("hello")
7366
Option
7467
-------
7568

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
7770
```julia
78-
Option{T} = Union{Identity{T}, Nothing}
71+
Option{T} = Union{Identity{T}, Const{Nothing}}
7972
```
8073

8174
Use it like
8275
```julia
8376
using DataTypesBasic
8477

8578
fo(a::Identity{String}) = a.value * "!"
86-
fo(a::Nothing) = "fallback behaviour"
79+
fo(a::Const{Nothing}) = "fallback behaviour"
8780

8881
fo(Option("hi")) # "hi!"
8982
fo(Option(nothing)) # "fallback behaviour"
@@ -101,7 +94,7 @@ Here an example for such a higher level perspective
10194
using DataTypesBasic
10295

10396
flatten(a::Identity) = a.value
104-
flatten(a::Nothing) = a
97+
flatten(a::Const) = a
10598

10699
# map a function over 2 Options, getting an option back
107100
function map2(f, a::Option{S}, b::Option{T}) where {S, T}
@@ -119,7 +112,7 @@ end # Identity("hi there")
119112

120113
map2(Option(1), Option()) do a, b
121114
a + b
122-
end # nothing
115+
end # Const(nothing)
123116
```
124117

125118
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
180173
Try
181174
----
182175

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.
184177
```julia
185178
Try{T} = Union{Const{<:Exception}, Identity{T}}
186179
```

test/Identity.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using DataTypesBasic
2+
using Suppressor
23

34
@test map(Identity(3)) do x
45
x + 4

0 commit comments

Comments
 (0)