blob: 748a1667498e94c55567dc874be3ecb16eaf0da0 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2021 CentraleSupelec, CEA-LIST
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Erwan Mahé (CentraleSupelec) - initial API and implementation
*******************************************************************************/
use std::fmt::Write;
use std::fmt::Display;
pub fn powerset<T>(s: &[T]) -> Vec<Vec<T>> where T: Clone {
(0..2usize.pow(s.len() as u32)).map(|i| {
s.iter().enumerate().filter(|&(t, _)| (i >> t) % 2 == 1)
.map(|(_, element)| element.clone())
.collect()
}).collect()
}
pub fn fold_vec_to_string<T: Display>(my_vec : &Vec<T>) -> String {
my_vec.iter().fold(String::new(),|mut s,n| {write!(s,"{}",n).ok(); s})
}