import Person, AmericanContent, OtherContent from lib
import Locale from std/locale
render_page = fn(input: Person) -> enum { american: AmericanContent, other: OtherContent } {
if input.locale.is("en-us") {
return @american(AmericanContent("I love paying taxes")
} else {
return @other(OtherContent("I love paying taxes and getting free school"))
}
}
p = Person("John Doe", 17, "nl_NL")
if @other(x) ?= render_page(p) {
print x
} else {
print "mmmm Americans"
}
import LIST from cool_people
import process from std
type ClubResult enum {
too_young,
not_on_list,
ok: Person,
}
can_access_club = fn(person: Person) -> ClubResult {
if person.age() < 21 {
return @too_young
}
if LIST.contains(person.name()) {
return @ok(person)
} else {
return @not_on_list
}
}
myself = Person("Mateo", 16)
result: ClubResult = can_access_club(myself)
if @too_young ?= result {
print "Error! You're too young"
process.exit()
}
if @not_on_list ?= result {
print "Go get cooler, you're not on the list"
process.exit()
}
if @ok(person) ?= result {
print "You can access the club, {person.name()}"
}
RFC for v2.0.0
Depends On:
Syntax