Skip to content

Commit

Permalink
Make variable names consistent with package name
Browse files Browse the repository at this point in the history
hasinitial -> hasinitialvalue
Initial -> InitialValue
SpecificInitial -> SpecificInitialValue
InitialOf -> InitialValueOf
  • Loading branch information
tkf committed Jul 8, 2019
1 parent 5e86172 commit 62b240f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ InitialValues
InitialValues.Init
InitialValues.@def
InitialValues.@disambiguate
InitialValues.hasinitial
InitialValues.hasinitialvalue
InitialValues.isknown
InitialValues.Initial
InitialValues.InitialValue
```
46 changes: 23 additions & 23 deletions src/InitialValues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end InitialValues
export Init

"""
Init(op) :: Initial
Init(op) :: InitialValue
Create a generic (left) identity for a binary operator `op`. For
general binary function, it provides an identity-like generic default
Expand All @@ -19,7 +19,7 @@ value (see `BangBang.push!!`).
```jldoctest
julia> using InitialValues
julia> Init(*) isa InitialValues.Initial
julia> Init(*) isa InitialValues.InitialValue
true
julia> Init(*) * 1
Expand All @@ -44,22 +44,22 @@ julia> Integer(Init(+))
0
```
"""
Init(::OP) where OP = InitialOf{OP}()
Init(::OP) where OP = InitialValueOf{OP}()

include("prettyexpr.jl")

"""
InitialValues.Initial
InitialValues.InitialValue
An abstract super type of all generic initial value types.
"""
abstract type Initial end
abstract type SpecificInitial{OP} <: Initial end
abstract type InitialValue end
abstract type SpecificInitialValue{OP} <: InitialValue end
# abstract type GenericIdentity <: AbstractIdentity end

struct InitialOf{OP} <: SpecificInitial{OP} end
struct InitialValueOf{OP} <: SpecificInitialValue{OP} end

function Base.show(io::IO, ::InitialOf{OP}) where {OP}
function Base.show(io::IO, ::InitialValueOf{OP}) where {OP}
if !get(io, :limit, false)
# Don't show full name in REPL etc.:
print(io, "InitialValues.")
Expand All @@ -72,17 +72,17 @@ function Base.show(io::IO, ::InitialOf{OP}) where {OP}
end
end

itypeof_impl(op) = :(SpecificInitial{typeof($op)})
itypeof_impl(op) = :(SpecificInitialValue{typeof($op)})
@eval itypeof(op) = $(itypeof_impl(:op))

"""
InitialValues.hasinitial(op) :: Bool
InitialValues.hasinitialvalue(op) :: Bool
# Examples
```jldoctest
julia> using InitialValues
julia> all(InitialValues.hasinitial, [
julia> all(InitialValues.hasinitialvalue, [
*,
+,
&,
Expand All @@ -94,15 +94,15 @@ julia> all(InitialValues.hasinitial, [
])
true
julia> InitialValues.hasinitial((x, y) -> x + y)
julia> InitialValues.hasinitialvalue((x, y) -> x + y)
false
```
"""
hasinitial(::OP) where OP = hasinitial(OP)
hasinitial(::Type) = false
hasinitialvalue(::OP) where OP = hasinitialvalue(OP)
hasinitialvalue(::Type) = false

"""
InitialValues.isknown(::Initial) :: Bool
InitialValues.isknown(::InitialValue) :: Bool
# Examples
```jldoctest
Expand All @@ -115,12 +115,12 @@ julia> InitialValues.isknown(Init((x, y) -> x + y))
false
```
"""
isknown(::SpecificInitial{OP}) where OP = hasinitial(OP)
isknown(::SpecificInitialValue{OP}) where OP = hasinitialvalue(OP)

def_impl(op, x, y) =
quote
$op(::$(itypeof_impl(op)), $x) = $y
InitialValues.hasinitial(::Type{typeof($op)}) = true
InitialValues.hasinitialvalue(::Type{typeof($op)}) = true
end

"""
Expand Down Expand Up @@ -182,12 +182,12 @@ end
@disambiguate Base.max Missing

const ZeroType = Union{
SpecificInitial{typeof(+)},
SpecificInitial{typeof(Base.add_sum)},
SpecificInitialValue{typeof(+)},
SpecificInitialValue{typeof(Base.add_sum)},
}
const OneType = Union{
SpecificInitial{typeof(*)},
SpecificInitial{typeof(Base.mul_prod)},
SpecificInitialValue{typeof(*)},
SpecificInitialValue{typeof(Base.mul_prod)},
}

Base.float(::ZeroType) = 0.0
Expand All @@ -201,10 +201,10 @@ Base.convert(::Type{T}, ::OneType) where {T <: Union{Number, AbstractString}} =

# Technically true, but could be a disaster in practice?:
#=
Base.convert(::Type{T}, ::Union{SpecificInitial{typeof(min)}}) where {T <: Number} =
Base.convert(::Type{T}, ::Union{SpecificInitialValue{typeof(min)}}) where {T <: Number} =
typemax(T)
Base.convert(::Type{T}, ::Union{SpecificInitial{typeof(max)}}) where {T <: Number} =
Base.convert(::Type{T}, ::Union{SpecificInitialValue{typeof(max)}}) where {T <: Number} =
typemin(T)
=#

Expand Down
6 changes: 3 additions & 3 deletions test/interop/test_bangbang.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module TestBangBang

using Test
using BangBang
using InitialValues: Init, hasinitial
using InitialValues: Init, hasinitialvalue

@testset begin
@test hasinitial(push!!)
@test hasinitial(append!!)
@test hasinitialvalue(push!!)
@test hasinitialvalue(append!!)
@test push!!(Init(push!!), 1) == [1]
@test append!!(Init(append!!), [1]) == [1]
end
Expand Down
16 changes: 8 additions & 8 deletions test/test_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module TestBasics

using Test
using InitialValues
using InitialValues: isknown, hasinitial
using InitialValues: isknown, hasinitialvalue


@testset for op in [*, +, |, &, min, max, Base.add_sum, Base.mul_prod]
@test op(Init(op), :anything) === :anything
@test hasinitial(op)
@test hasinitial(typeof(op))
@test hasinitialvalue(op)
@test hasinitialvalue(typeof(op))
@test isknown(Init(op))
end

Expand All @@ -27,11 +27,11 @@ end
end
end

@testset "hasinitial" begin
@test !hasinitial(-)
@test !hasinitial(typeof(-))
@test !hasinitial(Int)
@test !hasinitial(Type{Int})
@testset "hasinitialvalue" begin
@test !hasinitialvalue(-)
@test !hasinitialvalue(typeof(-))
@test !hasinitialvalue(Int)
@test !hasinitialvalue(Type{Int})
end

@testset "missing" begin
Expand Down
6 changes: 3 additions & 3 deletions test/test_def.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TestDef

using Test
using InitialValues: Init, hasinitial, isknown
using InitialValues: Init, hasinitialvalue, isknown

module CleanNameSpace
using InitialValues: @def, @disambiguate
Expand All @@ -14,7 +14,7 @@ end
@testset "CleanNameSpace" begin
add = CleanNameSpace.add
@test !isdefined(CleanNameSpace, :InitialValues)
@test hasinitial(add)
@test hasinitialvalue(add)
@test isknown(Init(add))
@test add(Init(add), :x) == "Got: :x"
@test add(Init(add), missing) == "Got: missing"
Expand All @@ -32,7 +32,7 @@ end
@testset "NonFunction" begin
add = NonFunction.add
@test !(add isa Function)
@test hasinitial(add)
@test hasinitialvalue(add)
@test isknown(Init(add))
@test add(Init(add), :x) == :x
@test add(Init(add), missing) == "Got: missing"
Expand Down

0 comments on commit 62b240f

Please sign in to comment.