Skip to content

Commit c55b174

Browse files
fix display in REPL as well as Juno
1 parent 36be128 commit c55b174

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/array_partition.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,28 @@ Base.done(A::ArrayPartition,state) = done(chain(A.x...),state)
7979

8080
Base.length(A::ArrayPartition) = sum((length(x) for x in A.x))
8181
Base.size(A::ArrayPartition) = (length(A),)
82+
Base.isempty(A::ArrayPartition) = (length(A) == 0)
83+
Base.indices(A::ArrayPartition) = ((indices(x) for x in A.x)...)
84+
function Base.indices(A::ArrayPartition,i::Int)
85+
if i == 1
86+
return Base.OneTo(length(A))
87+
else
88+
return Base.OneTo(1)
89+
end
90+
end
8291
Base.eachindex(A::ArrayPartition) = Base.OneTo(length(A))
8392

8493
# restore the type rendering in Juno
8594
Juno.@render Juno.Inline x::ArrayPartition begin
8695
fields = fieldnames(typeof(x))
8796
Juno.LazyTree(typeof(x), () -> [Juno.SubTree(Juno.Text("$f"), Juno.getfield′(x, f)) for f in fields])
8897
end
98+
Base.summary(A::ArrayPartition) = string(typeof(A), " with arrays:")
99+
Base.show(M::MIME"text/plain",A::ArrayPartition) = (Base.showarray.(A.x); nothing)
100+
Base.show(A::ArrayPartition) = (Base.show.(A.x); nothing)
101+
Base.display(A::ArrayPartition) = (println(summary(A));display.(A.x);nothing)
102+
Base.print(A::ArrayPartition) = show(A)
103+
Base.println(A::ArrayPartition) = show(A)
89104

90105
add_idxs(x,expr) = expr
91106
add_idxs{T<:ArrayPartition}(::Type{T},expr) = :($(expr).x[i])

0 commit comments

Comments
 (0)