Swap List.mapWithIndex arg1 args order to put the element first

This commit is contained in:
Jan Van Bruggen 2022-02-11 15:58:50 -07:00
parent 92e0f8714f
commit f47dbb5171
No known key found for this signature in database
GPG key ID: F4B9828637D6D81B
7 changed files with 8 additions and 8 deletions

View file

@ -279,7 +279,7 @@ map4 : List a, List b, List c, List d, (a, b, c, d -> e) -> List e
## This works like [List.map], except it also passes the index ## This works like [List.map], except it also passes the index
## of the element to the conversion function. ## of the element to the conversion function.
mapWithIndex : List before, (Nat, before -> after) -> List after mapWithIndex : List before, (before, Nat -> after) -> List after
## This works like [List.map], except at any time you can return `Err` to ## This works like [List.map], except at any time you can return `Err` to
## cancel the entire operation immediately, and return that #Err. ## cancel the entire operation immediately, and return that #Err.

View file

@ -1078,14 +1078,14 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
Box::new(list_type(flex(TVAR2))), Box::new(list_type(flex(TVAR2))),
); );
// mapWithIndex : List before, (Nat, before -> after) -> List after // mapWithIndex : List before, (before, Nat -> after) -> List after
{ {
let_tvars! { cvar, before, after}; let_tvars! { cvar, before, after};
add_top_level_function_type!( add_top_level_function_type!(
Symbol::LIST_MAP_WITH_INDEX, Symbol::LIST_MAP_WITH_INDEX,
vec![ vec![
list_type(flex(before)), list_type(flex(before)),
closure(vec![nat_type(), flex(before)], cvar, Box::new(flex(after))), closure(vec![flex(before), nat_type()], cvar, Box::new(flex(after))),
], ],
Box::new(list_type(flex(after))), Box::new(list_type(flex(after))),
) )

View file

@ -3300,7 +3300,7 @@ fn list_map(symbol: Symbol, var_store: &mut VarStore) -> Def {
lowlevel_2(symbol, LowLevel::ListMap, var_store) lowlevel_2(symbol, LowLevel::ListMap, var_store)
} }
/// List.mapWithIndex : List before, (Nat, before -> after) -> List after /// List.mapWithIndex : List before, (before, Nat -> after) -> List after
fn list_map_with_index(symbol: Symbol, var_store: &mut VarStore) -> Def { fn list_map_with_index(symbol: Symbol, var_store: &mut VarStore) -> Def {
lowlevel_2(symbol, LowLevel::ListMapWithIndex, var_store) lowlevel_2(symbol, LowLevel::ListMapWithIndex, var_store)
} }

View file

@ -5014,7 +5014,7 @@ fn run_higher_order_low_level<'a, 'ctx, 'env>(
} }
} }
ListMapWithIndex { xs } => { ListMapWithIndex { xs } => {
// List.mapWithIndex : List before, (Nat, before -> after) -> List after // List.mapWithIndex : List before, (before, Nat -> after) -> List after
let (list, list_layout) = load_symbol_and_layout(scope, xs); let (list, list_layout) = load_symbol_and_layout(scope, xs);
let (function, closure, closure_layout) = function_details!(); let (function, closure, closure_layout) = function_details!();

View file

@ -687,7 +687,7 @@ pub fn list_sort_with<'a, 'ctx, 'env>(
) )
} }
/// List.mapWithIndex : List before, (Nat, before -> after) -> List after /// List.mapWithIndex : List before, (before, Nat -> after) -> List after
pub fn list_map_with_index<'a, 'ctx, 'env>( pub fn list_map_with_index<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>, env: &Env<'a, 'ctx, 'env>,
roc_function_call: RocFunctionCall<'ctx>, roc_function_call: RocFunctionCall<'ctx>,

View file

@ -2363,7 +2363,7 @@ fn list_keep_errs() {
#[cfg(any(feature = "gen-llvm"))] #[cfg(any(feature = "gen-llvm"))]
fn list_map_with_index() { fn list_map_with_index() {
assert_evals_to!( assert_evals_to!(
"List.mapWithIndex [0,0,0] (\\index, x -> Num.intCast index + x)", "List.mapWithIndex [0,0,0] (\\x, index -> Num.intCast index + x)",
RocList::from_slice(&[0, 1, 2]), RocList::from_slice(&[0, 1, 2]),
RocList<i64> RocList<i64>
); );

View file

@ -23,7 +23,7 @@ echo = \shout ->
shout shout
|> Str.toUtf8 |> Str.toUtf8
|> List.mapWithIndex |> List.mapWithIndex
(\i, _ -> (\_, i ->
length = (List.len (Str.toUtf8 shout) - i) length = (List.len (Str.toUtf8 shout) - i)
phrase = (List.split (Str.toUtf8 shout) length).before phrase = (List.split (Str.toUtf8 shout) length).before