Function tupleops::apply [−][src]
pub fn apply<F, Tpl>(func: F, tpl: Tpl) -> Apply<F, Tpl> where
(F, Tpl): TupleApply<F, Tpl>,
This is supported on crate feature
apply
only.Expand description
Call a function with the tuples members as arguments.
The function F can be &Fn
or &mut FnMut
.
use tupleops::apply;
fn add3(a: u32, b: u32, c: u32) -> u32 {
a + b + c
}
let tpl3 = (1, 2, 3);
assert_eq!(apply(&add3, tpl3), 6);
use tupleops::apply;
let mut counter = 0;
let mut prefixsum3 = |a, b, c| {
counter += a + b + c;
counter
};
assert_eq!(apply(&mut prefixsum3, (1, 2, 3)), 6);
assert_eq!(apply(&mut prefixsum3, (4, 5, 6)), 21);
assert_eq!(apply(&mut prefixsum3, (7, 8, 9)), 45);
See also: Apply, TupleApply.