In this exercise you're going to write a generic (/ magical!) TreasureChest, to store some treasure.
Define a TreasureChest{T} parametric type with two fields.
password field of type String, which will be used to store the password of the treasure chest.treasure field of type T, which will be used to store the treasure.
This value is generic so that the treasure can be anything.julia> chest = TreasureChest{String}("password", "gold")
TreasureChest{String}("password", "gold")This function should take two arguments.
String (for trying a password)TreasureChest typeThis function should check the provided password attempt against the password in the TreasureChest.
nothing.julia> get_treasure("password", chest)
"gold"
julia> get_treasure("wrong", chest)
# no output
julia> isnothing(get_treasure("wrong", chest))
trueThis function should take two arguments.
n.TreasureChest{T} type.The function should return a new TreasureChest{Vector{T}}, with
Vector{T} of length n, and the original treasure repeated n times.julia> multiply_treasure(3, chest)
TreasureChest{Vector{String}}("password", ["gold", "gold", "gold"])In this exercise you're going to write a generic (/ magical!) TreasureChest, to store some treasure.
Define a TreasureChest{T} parametric type with two fields.
password field of type String, which will be used to store the password of the treasure chest.treasure field of type T, which will be used to store the treasure.
This value is generic so that the treasure can be anything.julia> chest = TreasureChest{String}("password", "gold")
TreasureChest{String}("password", "gold")This function should take two arguments.
String (for trying a password)TreasureChest typeThis function should check the provided password attempt against the password in the TreasureChest.
nothing.julia> get_treasure("password", chest)
"gold"
julia> get_treasure("wrong", chest)
# no output
julia> isnothing(get_treasure("wrong", chest))
trueThis function should take two arguments.
n.TreasureChest{T} type.The function should return a new TreasureChest{Vector{T}}, with
Vector{T} of length n, and the original treasure repeated n times.julia> multiply_treasure(3, chest)
TreasureChest{Vector{String}}("password", ["gold", "gold", "gold"])