Skip to content

Commit 377eaeb

Browse files
Stephan SahmStephan Sahm
authored andcommitted
adding Base.getindex to Identity, analog to Base.get
1 parent 1ad16fe commit 377eaeb

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

src/Identity.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ isidentity(other) = false
2929
Base.length(::Identity) = 1
3030

3131
Base.get(a::Identity) = a.value
32+
Base.getindex(a::Identity) = a.value
33+
3234
Base.eltype(::Type{<:Identity{T}}) where T = T
3335
Base.eltype(::Type{<:Identity}) = Any
3436

test/Identity.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ end == Identity(3 + 4)
1515
@test length(Identity([1,2,3,4])) == 1
1616

1717
@test get(Identity(42)) == 42
18+
@test Identity(42)[] == 42
1819

1920
@test isidentity(Identity(4))
2021
@test !isidentity(Const(3))

0 commit comments

Comments
 (0)