Content deleted Content added
→PHP: templating 2 bare-URL references |
→S-Lang: Add examples for Rust |
||
Line 1,669:
Ruby also supports many other useful operations on hashes, such as merging hashes, selecting or rejecting elements that meet some criteria, inverting (swapping the keys and values), and flattening a hash into an array.
===Rust===
[[Rust (programming language)|Rust]] has a hash map:
<syntaxhighlight lang="text">
use std::collections::HashMap;
let mut phone_book = HashMap::new();
phone_book.insert("Sally Smart", "555-9999");
phone_book.insert("John Doe", "555-1212");
phone_book.insert("J. Random Hacker", "555-1337");
</syntaxhighlight>
You can also loop through an associated array in a number of ways:
<syntaxhighlight lang="text">
for (name, number) in &phone_book {
println!("{} {}", name, number);
}
</syntaxhighlight>
===S-Lang===
|