2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-12-18 22:48:23 -06:00
|
|
|
fn repeat(x: &uint) -> ~[uint] { ~[*x, *x] }
|
2012-04-11 23:45:18 -05:00
|
|
|
|
2012-12-18 22:48:23 -06:00
|
|
|
fn incd_if_even(x: &uint) -> Option<uint> {
|
|
|
|
if (*x % 2u) == 0u {Some(*x + 1u)} else {None}
|
2012-04-11 23:45:18 -05:00
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!((~[1u, 3u]).flat_map_to_vec(repeat) == ~[1u, 1u, 3u, 3u]);
|
|
|
|
assert!((~[]).flat_map_to_vec(repeat) == ~[]);
|
2013-04-24 19:35:49 -05:00
|
|
|
assert!(old_iter::flat_map_to_vec(&None::<uint>, repeat) == ~[]);
|
|
|
|
assert!(old_iter::flat_map_to_vec(&Some(1u), repeat) == ~[1u, 1u]);
|
|
|
|
assert!(old_iter::flat_map_to_vec(&Some(2u), repeat) == ~[2u, 2u]);
|
2012-04-11 23:45:18 -05:00
|
|
|
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!((~[1u, 2u, 5u]).flat_map_to_vec(incd_if_even) == ~[3u]);
|
|
|
|
assert!((~[]).flat_map_to_vec(incd_if_even) == ~[]);
|
2013-04-24 19:35:49 -05:00
|
|
|
assert!(old_iter::flat_map_to_vec(&None::<uint>, incd_if_even) == ~[]);
|
|
|
|
assert!(old_iter::flat_map_to_vec(&Some(1u), incd_if_even) == ~[]);
|
|
|
|
assert!(old_iter::flat_map_to_vec(&Some(2u), incd_if_even) == ~[3u]);
|
2012-12-17 22:36:12 -06:00
|
|
|
}
|