On Fri, Oct 16, 2015 at 9:08 PM, Chris Stook <[email protected]> wrote: > Is it possible to overload show for an array of a specific type? See > example below. > > In [1]: > type a_type > b_element :: Int64 > c_element :: Int64 > end > d_array = [a_type(1,2),a_type(3,4),a_type(5,6)] > > Out[1]: > 3-element Array{a_type,1}: > a_type(1,2) > a_type(3,4) > a_type(5,6) > > In [2]: > function Base.show(io::IO, a::Array{a_type,1}) > println(io,rpad("b_element",10),rpad("c_element",10)) > for e in a > println(io,rpad(e.b_element,10),rpad(e.c_element,10)) > end > end > > Out[2]: > show (generic function with 105 methods) > > In [3]: > show(d_array) > b_element c_element > 1 2 > 3 4 > 5 6 > > In [4]: > d_array > > Out[4]: > 3-element Array{a_type,1}: > a_type(1,2) > a_type(3,4) > a_type(5,6) >
Quote from http://julia.readthedocs.org/en/latest/stdlib/io-network/#Base.writemime > The display functions ultimately call writemime in order to write an object x > as a given mime type to a given I/O stream (usually a memory buffer), if > possible. ``` julia> type A end julia> A[] 0-element Array{A,1} julia> Base.writemime(io::IO, ::MIME"text/plain", a::Vector{A}) = print(io, "nothing") writemime (generic function with 26 methods) julia> A[] nothing ``` > > > > - Chris
