Function mocktave::wrap

source ·
pub fn wrap<Y, Z>(function: String) -> Box<dyn Fn(Y) -> Z>where
    Y: IntoIterator,
    <Y as IntoIterator>::Item: ToString,
    Z: From<OctaveType>,
Expand description

This function provides the ability to wrap Octave functions for convenient later use.

let primes = mocktave::wrap("primes".into());
let all_primes_less_than_100: Vec<Vec<i32>> = primes([100]);
assert_eq!(all_primes_less_than_100, vec![vec![2_i32, 3, 5, 7,
    11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
    71, 73, 79, 83, 89, 97]])

Use functions with multiple inputs

let max = mocktave::wrap("max".into());
let should_be_101: i32 = max([100, 101]);
assert_eq!(should_be_101, 101_i32);

And even use functions with disimilar types

use mocktave::OctaveType;
let norm = mocktave::wrap("norm".into());
let x = [
    OctaveType::Matrix(vec![vec![0.0; 2]; 2]),
    OctaveType::Scalar(2.0)
];
let should_be_zero: f64 = norm(x);
assert_eq!(should_be_zero, 0.0_f64);