Update worlds example.

This commit is contained in:
Jesse Brault 2025-09-19 12:44:57 -05:00
parent 9e3d71d73b
commit 49a96eba85
2 changed files with 19 additions and 16 deletions

View File

@ -1,16 +0,0 @@
class World(pub name: String, pub color: String)
pub static worlds = [
World('Mercury', 'Red'),
World('Earth', 'Blue'),
World('Jupiter', 'Orange')
]
pub static getWorld(color: String) -> String = worlds
.find { it.color == color }
.map { it.name }
.expect "No world has the given color ${color}."
end
fn main()
println "Hello, ${World::getWorld('Blue')}!"
end

19
examples/worlds.dm Normal file
View File

@ -0,0 +1,19 @@
class World(pub name: String, pub color: String) end
fn getWorlds() -> List<World> = [
World('Mercury', 'Red'),
World('Earth', 'Blue'),
World('Jupiter', 'Orange')
]
fn findWorldByColor(worlds: List<World>, color: String) -> String
worlds.find { it.color == color }
.map { it.name }
.expect "No world has the given color ${color}"
end
fn main()
let worlds = getWorlds()
let blueWorld = findWorldByColor(worlds, 'Blue')
println "Hello, ${blueWorld}!"
end