Skip to content

Instantly share code, notes, and snippets.

@lissahyacinth
Last active August 11, 2019 23:02
Show Gist options
  • Save lissahyacinth/0999c225a7936155cb1cfd31c5fb7400 to your computer and use it in GitHub Desktop.
Save lissahyacinth/0999c225a7936155cb1cfd31c5fb7400 to your computer and use it in GitHub Desktop.
RustDyn
pub fn map_column<'a, ColumnType: 'static, A: 'static, B: 'static>(
column_data: &'a ColumnInformation<ColumnType>,
column_idx: usize,
indexes: &[usize],
map_fn: A,
) -> Box<dyn Iterator<Item = B> + 'a>
where
A: Fn(ColumnType) -> B,
ColumnType: std::clone::Clone,
{
let column_indexes: Vec<usize> = indexes
.iter()
.map(|idx| (column_data.columns * *idx) + column_idx)
.collect::<Vec<usize>>();
Box::new(
column_indexes
.into_iter()
.map(move |index| map_fn(column_data.predictors[index].clone())),
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment