Search a list of records: Difference between revisions

Added Rust
(Added Rust)
Line 2,160:
puts cities.find {|city| city[:name][0] == "A"}[:population] # => 4.58
</lang>
 
=={{header|Rust}}==
<lang Rust>struct City {
name: &'static str,
population: f64,
}
 
fn main() {
let cities = [
City {
name: "Lagos",
population: 21.0,
},
City {
name: "Cairo",
population: 15.2,
},
City {
name: "Kinshasa-Brazzaville",
population: 11.3,
},
City {
name: "Greater Johannesburg",
population: 7.55,
},
City {
name: "Mogadishu",
population: 5.85,
},
City {
name: "Khartoum-Omdurman",
population: 4.98,
},
City {
name: "Dar Es Salaam",
population: 4.7,
},
City {
name: "Alexandria",
population: 4.58,
},
City {
name: "Abidjan",
population: 4.4,
},
City {
name: "Casablanca",
population: 3.98,
},
];
 
println!(
"{:?}",
cities.iter().position(|city| city.name == "Dar Es Salaam")
);
println!(
"{:?}",
cities
.iter()
.find(|city| city.population < 5.0)
.map(|city| city.name)
);
println!(
"{:?}",
cities
.iter()
.find(|city| city.name.starts_with('A'))
.map(|city| city.population)
);
}
</lang>
{{Out}}
<pre>Some(6)
Some("Khartoum-Omdurman")
Some(4.58)</pre>
 
=={{header|Scala}}==
Anonymous user