RosettaCodeData/Task/Constrained-genericity/V-(Vlang)/constrained-genericity.v
2026-04-30 12:34:36 -04:00

20 lines
380 B
V

interface Eatable {
eat()
}
type Foodbox = []Eatable
type Peelfirst = string
fn (f Peelfirst) eat() {
// peel code goes here
println("mm, that ${f} was good!")
}
fn main() {
mut fb := Foodbox{}
fb << [Peelfirst("banana"), Peelfirst("mango")]
// fb would print as `[Eatable(Peelfirst(banana)), Eatable(Peelfirst(mango))]`
f0 := fb[0]
f0.eat()
}