add demo docs

This commit is contained in:
nightwing 2013-04-06 12:53:21 +04:00
commit 73f299d3f0
12 changed files with 243 additions and 9 deletions

View file

@ -0,0 +1,20 @@
use core::rand::RngUtil;
fn main() {
for ["Alice", "Bob", "Carol"].each |&name| {
do spawn {
let v = rand::Rng().shuffle([1, 2, 3]);
for v.each |&num| {
print(fmt!("%s says: '%d'\n", name, num + 1))
}
}
}
}
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
let mut accumulator = ~[];
for vec::each(vector) |element| {
accumulator.push(function(element));
}
return accumulator;
}