using Dates
struct Person
::String
FirstName::String
LastName::Date
DOB::Float64
Height::Float64
Weightend
11 Types
Julia’s type system is what defines its usage and guides its high performance.
User-defined types are created using struct
.
Defining variable types is optional, but helps the compiler produce optimized (i.e. very fast) code.
In the following example we start by loading the Dates
package to use the Date
type within the struct definition, along with the base String
and Float64
types:
typeof(Person)
DataType
= Person("Julia", "Lang", Date(2012, 2, 12), 1.73, 51) p
Person("Julia", "Lang", Date("2012-02-12"), 1.73, 51.0)
11.1 Methods
Get all methods that can be applied to a DataType with methodswith()
:
methodswith(Date)
43-element Vector{Method}:
- +(x::Dates.Date, y::Dates.Day) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:81
- +(x::Dates.Date, y::Dates.Week) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:79
- +(x::Dates.Date, y::Dates.Quarter) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:75
- +(dt::Dates.Date, z::Dates.Month) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:56
- +(dt::Dates.Date, y::Dates.Year) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:29
- +(dt::Dates.Date, t::Dates.Time) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:21
- +(t::Dates.Time, dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:22
- -(x::Dates.Date, y::Dates.Day) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:82
- -(x::Dates.Date, y::Dates.Week) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:80
- -(x::Dates.Date, y::Dates.Quarter) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:76
- -(dt::Dates.Date, z::Dates.Month) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:68
- -(dt::Dates.Date, y::Dates.Year) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:37
- (::Colon)(a::T, b::T) where T<:Date in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/ranges.jl:7
- convert(::Type{Dates.Day}, dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/conversions.jl:37
- convert(::Type{Dates.DateTime}, dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/conversions.jl:30
- floor(dt::Dates.Date, p::Dates.Day) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/rounding.jl:73
- floor(dt::Dates.Date, p::Dates.Week) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/rounding.jl:66
- floor(dt::Dates.Date, p::Dates.Quarter) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/rounding.jl:61
- floor(dt::Dates.Date, p::Dates.Month) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/rounding.jl:51
- floor(dt::Dates.Date, p::Dates.Year) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/rounding.jl:45
- print(io::IO, dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/io.jl:714
- show(io::IO, ::MIME{Symbol("text/plain")}, dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/io.jl:726
- show(io::IO, dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/io.jl:728
- trunc(dt::Dates.Date, p::Type{Dates.Day}) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:7
- trunc(dt::Dates.Date, p::Type{Dates.Month}) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:6
- trunc(dt::Dates.Date, p::Type{Dates.Quarter}) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:5
- trunc(dt::Dates.Date, p::Type{Dates.Year}) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:4
- typemax(::Union{Dates.Date, Type{Dates.Date}}) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/types.jl:446
- typemin(::Union{Dates.Date, Type{Dates.Date}}) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/types.jl:447
- Dates.DateTime(dt::Dates.Date, t::Dates.Time) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/types.jl:394
- Dates.Day(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/periods.jl:34
- Dates.Month(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/periods.jl:34
- Dates.Quarter(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/periods.jl:34
- Dates.Week(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/periods.jl:34
- Dates.Year(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/periods.jl:34
- firstdayofmonth(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:84
- firstdayofquarter(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:157
- firstdayofweek(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:52
- firstdayofyear(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:119
- lastdayofmonth(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:100
- lastdayofquarter(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:180
- lastdayofweek(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:68
- lastdayofyear(dt::Dates.Date) in Dates at /Users/egenn/.julia/juliaup/julia-1.10.4+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/Dates/src/adjusters.jl:135
Get all data types that have methods defined for a generic with methods()
:
methods(sort)
# 4 methods for generic function sort from Base:
- sort(r::AbstractUnitRange) in Base at range.jl:1410
- sort(r::AbstractRange) in Base at range.jl:1413
- sort(v::AbstractVector; kws...) in Base.Sort at sort.jl:1489
- sort(A::AbstractArray{T}; dims, alg, lt, by, rev, order, scratch) where T in Base.Sort at sort.jl:1783