diff --git a/examples/d_string.dm b/examples/d_string.dm deleted file mode 100644 index 1112a56..0000000 --- a/examples/d_string.dm +++ /dev/null @@ -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 diff --git a/examples/worlds.dm b/examples/worlds.dm new file mode 100644 index 0000000..8de9654 --- /dev/null +++ b/examples/worlds.dm @@ -0,0 +1,19 @@ +class World(pub name: String, pub color: String) end + +fn getWorlds() -> List = [ + World('Mercury', 'Red'), + World('Earth', 'Blue'), + World('Jupiter', 'Orange') +] + +fn findWorldByColor(worlds: List, 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