Skip to content

Commit 65eb4d1

Browse files
no longer converting Const to Identity
1 parent 9909f53 commit 65eb4d1

4 files changed

Lines changed: 9 additions & 6 deletions

File tree

Changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.0.0] - ?????
910
### Added
1011
- `Base.get` and `Base.getindex` are now both implemented for `Const` (like they are implemented already for `Identity`), to simplify working with `Const`.
1112

1213
### Fixed
1314
- `Option(3)` works now
1415
- The constructors `Const{ElementType}(value)` and `Identity{ElementType}(value)` had been removed already, however were still used. Maybe this now gave errors because of newer julia version, don't know, but now everything uses `Const(value)` and `Identity(value)` instead.
16+
17+
### Removed
18+
- `Option{T}(value::T)` didn't work and is removed now, as it does not provide any benefit anylonger, which is a breaking change
19+
- `Option{T}()` is also removed for completeness, which is a breaking change
20+
- `Const` no longer converts to `Identity`. This was added so that a `Const` nested within an `Identity` can be flattened. However, there is a better alternative, namely now the `flatmap` operator on `Identity` just strips away the outer Identity, without any call to `convert`. This is simpler and more convenient approach which also makes the hacky conversion no longer needed. Still this is a breaking change.
21+
1522
## [1.0.0] - 2020-07-19
1623
### Added
1724
- CI via GitHubActions

src/Identity.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Base.iterate(a::Identity) = a.value, nothing
3939
Base.iterate(a::Identity, state) = state
4040
Base.foreach(f, a::Identity) = begin f(a.value); nothing; end
4141
Base.map(f, a::Identity) = Identity(f(a.value))
42-
Base.Iterators.flatten(a::Identity) = convert(Identity, a.value)
42+
# for convenience, Identity does not use convert, whatever monad is returned is valid, providing maximum flexibility.
43+
Base.Iterators.flatten(a::Identity) = a.value
4344

4445
Base.convert(::Type{Identity{T}}, x::Identity{T}) where {T} = x
4546
Base.convert(::Type{Identity{T}}, x::Identity) where {T} = Identity(convert(T, x.value))

src/convert.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ end
2121
# Identity
2222
# --------
2323

24-
# Const are just passed through when asked to convert to identity
25-
# this is intended special behaviour in order for Identity + Const to work together as Option/Either
26-
Base.convert(::Type{Identity}, x::Const) = x
2724
# ContextManager is executed
2825
Base.convert(::Type{<:Identity}, x::ContextManager) = Identity(run(x))
2926

test/convert.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ using DataTypesBasic
99
@test convert(Vector, Const(43)) == []
1010
@test convert(Vector, @ContextManager cont -> cont(2)) == [2]
1111

12-
@test convert(Identity, Option()) == Option()
13-
@test convert(Identity, Const(:error)) == Const(:error)
1412
@test convert(Identity, @ContextManager cont -> cont(2)) == Identity(2)
1513
@test_throws MethodError convert(Identity, [1,2,3])
1614

0 commit comments

Comments
 (0)