Quick way to know the valid values of a function parameter (find all values under a concrete type)

Sorry for not well-described question in advance, if there’s anything unclear, please leave a reply!

Brief question

What I would like to ask is that:

How to know the valid options for a parameter?

For exmaple, if I want to use a specific function, and it said that its first parameter is restricted to be of type IO, then how could I knew that the possible options would be stderr, stdout, stdin?

Detailed description for my question

Suppose now I want to use a function / type…, say ConsoleLogger(), I could get its definition by REPL’s help mode / hover help in IDE to check the documentation, for example, in the REPL help mode, we have:

help?> ConsoleLogger
search: ConsoleLogger

  ConsoleLogger(stream=stderr, min_level=Info; meta_formatter=default_metafmt,
                show_limited=true, right_justify=0)

# some more descriptions

I would then wanted to know what else values I could choose for the parameter stream, in the IDE it would show field types, and in the REPL we could search by fieldtypes():

julia> fieldtypes(ConsoleLogger)
(IO, Base.CoreLogging.LogLevel, Any, Bool, Int64, Dict{Any, Int64})

Now I knew that stream should be an instance of IO, but seraching for IO in the help mode would only show its subtypes:

help?> IO
search: IO IOStream IOBuffer IOContext fdio Union union union! Union{} UnionAll Rational

  No documentation found.

  Summary
  ≡≡≡≡≡≡≡≡≡

  abstract type IO <: Any

  Subtypes
  ≡≡≡≡≡≡≡≡≡≡

  Base.AbstractPipe
  Base.DevNull
  Base.Filesystem.AbstractFile
  Base.GenericIOBuffer
  Base.LibuvStream
  Base.SecretBuffer
  Base64.Base64DecodePipe
  Base64.Base64EncodePipe
  Core.CoreSTDERR
  Core.CoreSTDOUT
  IOStream
  Mmap.Anonymous

But from this result, I could now know whether each of the listed things are abstract types or concrete types, I would need to deep further to check for each listed things, then even until I found a concrete type, I still could not know what values are under this concrete type.

I’m new to Julia and I haven’t found related solution from the julia docs and forum posts, if this could be found by some keyword or I missed some part from the docs, please let me know and sorry for asking repeated question!

Welcome to the Julia discourse forum :waving_hand:

There is subtypes

julia> subtypes(IO)
12-element Vector{Any}:
 Base.AbstractPipe
 Base.DevNull
 Base.Filesystem.AbstractFile
 Base.GenericIOBuffer
 Base.LibuvStream
 Base.SecretBuffer
 Base64.Base64DecodePipe
 Base64.Base64EncodePipe
 Core.CoreSTDERR
 Core.CoreSTDOUT
 IOStream
 REPL.LimitIO

this lists all subtypes of a type at the type of asking, since loading another package might introduce further such types.

Note that this is about types not values – for example Float64 would be the type 1.23 its value, so be also careful with terminology.

1 Like