// 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 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. fn repeat(x: &uint) -> ~[uint] { ~[*x, *x] } fn incd_if_even(x: &uint) -> Option { if (*x % 2u) == 0u {Some(*x + 1u)} else {None} } fn main() { assert (~[1u, 3u]).flat_map_to_vec(repeat) == ~[1u, 1u, 3u, 3u]; assert (~[]).flat_map_to_vec(repeat) == ~[]; assert None.flat_map_to_vec(repeat) == ~[]; assert Some(1u).flat_map_to_vec(repeat) == ~[1u, 1u]; assert Some(2u).flat_map_to_vec(repeat) == ~[2u, 2u]; assert (~[1u, 2u, 5u]).flat_map_to_vec(incd_if_even) == ~[3u]; assert (~[]).flat_map_to_vec(incd_if_even) == ~[]; assert None.flat_map_to_vec(incd_if_even) == ~[]; assert Some(1u).flat_map_to_vec(incd_if_even) == ~[]; assert Some(2u).flat_map_to_vec(incd_if_even) == ~[3u]; }