pub fn map_closure(mut params: Vec<Box<dyn Value>>, ctx: LockableContext) -> ValueResult {
    if params.len() == 2 {
        let first = params.remove(0);
        let second = params.remove(0);
        let type_name = first.get_type_name();
        match type_name {
            "list" => {
                let first = first.downcast::<ListValue>().unwrap();
                let mut vec: Vec<Box<dyn Value>> = Vec::with_capacity(first.values.len());
                for (i, value) in first.values.into_iter().enumerate() {
                    let index = Box::new(IntegerValue { value: i as i64 });
                    vec.push(second.call(vec![value, index], ctx.clone())?);
                }
                ListValue::boxed(vec)
            }
            "dict" => {
                let first = first.downcast::<DictValue>().unwrap();
                let mut dict: HashMap<String, Box<dyn Value>> =
                    HashMap::with_capacity(first.values.len());
                for (key, value) in first.values.into_iter() {
                    let key_value = Box::new(StringValue { value: key.clone() });
                    dict.insert(key, second.call(vec![key_value, value], ctx.clone())?);
                }
                DictValue::boxed(dict)
            }
            _ => {
                CashError::InvalidArguments(type_name.to_owned(), "List or Dict".to_owned()).boxed()
            }
        }
    } else {
        CashError::InvalidParameterCount(params.len(), 2).boxed()
    }
}
/// Takes exactly 2 params
/// first: a list/dict to be mapped
/// second: the function, which will receive either the value and index of the list item, or the key and value of the dict item
Takes exactly 2 params
first: a list/dict to be mapped
second: the function, which will receive either the value and index of the list item, or the key and value of the dict item
Takes exactly 2 params first : a list / dict to be mapped second : the function which will receive either the value and index of the list item or the key and value of the dict item
pub fn map_closure(mut params: Vec<Box<dyn Value>>, ctx: LockableContext) -> ValueResult {
    if params.len() == 2 {
        let first = params.remove(0);
        let second = params.remove(0);
        let type_name = first.get_type_name();
        match type_name {
            "list" => {
                let first = first.downcast::<ListValue>().unwrap();
                let mut vec: Vec<Box<dyn Value>> = Vec::with_capacity(first.values.len());
                for (i, value) in first.values.into_iter().enumerate() {
                    let index = Box::new(IntegerValue { value: i as i64 });
                    vec.push(second.call(vec![value, index], ctx.clone())?);
                }
                ListValue::boxed(vec)
            }
            "dict" => {
                let first = first.downcast::<DictValue>().unwrap();
                let mut dict: HashMap<String, Box<dyn Value>> =
                    HashMap::with_capacity(first.values.len());
                for (key, value) in first.values.into_iter() {
                    let key_value = Box::new(StringValue { value: key.clone() });
                    dict.insert(key, second.call(vec![key_value, value], ctx.clone())?);
                }
                DictValue::boxed(dict)
            }
            _ => {
                CashError::InvalidArguments(type_name.to_owned(), "List or Dict".to_owned()).boxed()
            }
        }
    } else {
        CashError::InvalidParameterCount(params.len(), 2).boxed()
    }
}
pub fn map_closure ( mut params : Vec < Box < dyn Value > > , ctx : LockableContext ) -> ValueResult { if params . len ( ) == 2 { let first = params . remove ( 0 ) ; let second = params . remove ( 0 ) ; let type_name = first . get_type_name ( ) ; match type_name { " " => { let first = first . downcast :: < ListValue > ( ) . unwrap ( ) ; let mut vec : Vec < Box < dyn Value > > = Vec :: with_capacity ( first . values . len ( ) ) ; for ( i , value ) in first . values . into_iter ( ) . enumerate ( ) { let index = Box :: new ( IntegerValue { value : i as i64 } ) ; vec . push ( second . call ( vec ! [ value index ] , ctx . clone ( ) ) ? ) ; } ListValue :: boxed ( vec ) } " " => { let first = first . downcast :: < DictValue > ( ) . unwrap ( ) ; let mut dict : HashMap < String , Box < dyn Value > > = HashMap :: with_capacity ( first . values . len ( ) ) ; for ( key , value ) in first . values . into_iter ( ) { let key_value = Box :: new ( StringValue { value : key . clone ( ) } ) ; dict . insert ( key , second . call ( vec ! [ key_value value ] , ctx . clone ( ) ) ? ) ; } DictValue :: boxed ( dict ) } _ => { CashError :: InvalidArguments ( type_name . to_owned ( ) , " " . to_owned ( ) ) . boxed ( ) } } } else { CashError :: InvalidParameterCount ( params . len ( ) , 2 ) . boxed ( ) } }
Takes exactly 2 params
first: a list/dict to be mapped
second: the function, which will receive either the value and index of the list item, or the key and value of the dict item
Takes exactly 2 params first : a list / dict to be mapped second : the function which will receive either the value and index of the list item or the key and value of the dict item
params
Vec<Box<dyn Value>>
ctx
LockableContext
params
Vec<Box<dyn Value>>
ctx
LockableContext