Skip to content

Commit

Permalink
Simplify show methods by using iteration for Parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
SoongNoonien committed Oct 24, 2024
1 parent 133a57e commit 0674ea1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/Parameter.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base: show
import Base: show, getindex, eltype, length, iterate

@doc raw"""
Parameter
Expand Down Expand Up @@ -32,6 +32,14 @@ struct Parameters
exceptions::Vector{UPolyFrac}
end

getindex(p::Parameters, i::Integer) = p.params[i]

eltype(::Type{Parameters}) = Parameter

Check warning on line 37 in src/Parameter.jl

View check run for this annotation

Codecov / codecov/patch

src/Parameter.jl#L37

Added line #L37 was not covered by tests

length(p::Parameters) = length(p.params)

iterate(p::Parameters, state::Integer=1) = state > length(p) ? nothing : (p[state], state+1)

function Parameters(p::Vector{Parameter})
return Parameters(p,UPolyFrac[])
end
Expand Down
8 changes: 4 additions & 4 deletions src/Show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ julia> [g[3]]
function show(io::IO, ::MIME"text/plain", c::AbstractGenericCharacter)
io = pretty(io)
println(io, "Generic character of ", parent(c).importname, Indent())
if c isa GenericCharacter && !isempty(c.params.params)
if !isempty(parameters(c))
println(io, "with parameters ", Indent())
print(io, c.params)
print(io, parameters(c))
if !isempty(c.substitutions)
print(io, ", substitutions: $(join(c.substitutions, ", "))")
end
Expand Down Expand Up @@ -121,9 +121,9 @@ julia> [conjugacy_class_type(g, 3)]
function show(io::IO, ::MIME"text/plain", c::AbstractGenericConjugacyClass)
io = pretty(io)
println(io, "Generic conjugacy class of ", parent(c).importname, Indent())
if c isa GenericConjugacyClass && !isempty(parent(c).classparams[c.index].params)
if !isempty(parameters(c))
println(io, "with parameters ", Indent())
print(io, parent(c).classparams[c.index])
print(io, parameters(c))
if !isempty(c.substitutions)
print(io, ", substitutions: $(join(c.substitutions, ", "))")
end
Expand Down

0 comments on commit 0674ea1

Please sign in to comment.