mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Merge branch 'trunk' into deps
This commit is contained in:
commit
3df3e2f0d5
5 changed files with 45 additions and 0 deletions
1
AUTHORS
1
AUTHORS
|
@ -47,3 +47,4 @@ Joshua Warner <joshuawarner32@gmail.com>
|
|||
Luiz Carlos L. G. de Oliveira <luizcarlos1405@gmail.com>
|
||||
Oleksii Skidan <al.skidan@gmail.com>
|
||||
Martin Janiczek <martin@janiczek.cz>
|
||||
Eric Newbury <enewbury@users.noreply.github.com>
|
||||
|
|
|
@ -979,6 +979,13 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
|
|||
Box::new(list_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// dropFirst : List elem -> List elem
|
||||
add_top_level_function_type!(
|
||||
Symbol::LIST_DROP_FIRST,
|
||||
vec![list_type(flex(TVAR1))],
|
||||
Box::new(list_type(flex(TVAR1))),
|
||||
);
|
||||
|
||||
// swap : List elem, Nat, Nat -> List elem
|
||||
add_top_level_function_type!(
|
||||
Symbol::LIST_SWAP,
|
||||
|
|
|
@ -92,6 +92,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
|
|||
LIST_MAP4 => list_map4,
|
||||
LIST_DROP => list_drop,
|
||||
LIST_DROP_AT => list_drop_at,
|
||||
LIST_DROP_FIRST => list_drop_first,
|
||||
LIST_DROP_LAST => list_drop_last,
|
||||
LIST_SWAP => list_swap,
|
||||
LIST_MAP_WITH_INDEX => list_map_with_index,
|
||||
|
@ -2049,6 +2050,30 @@ fn list_drop_at(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
)
|
||||
}
|
||||
|
||||
fn list_drop_first(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let list_var = var_store.fresh();
|
||||
let index_var = var_store.fresh();
|
||||
let num_var = Variable::NAT;
|
||||
let num_precision_var = Variable::NATURAL;
|
||||
|
||||
let body = RunLowLevel {
|
||||
op: LowLevel::ListDropAt,
|
||||
args: vec![
|
||||
(list_var, Var(Symbol::ARG_1)),
|
||||
(index_var, int(num_var, num_precision_var, 0)),
|
||||
],
|
||||
ret_var: list_var,
|
||||
};
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
vec![(list_var, Symbol::ARG_1)],
|
||||
var_store,
|
||||
body,
|
||||
list_var,
|
||||
)
|
||||
}
|
||||
|
||||
/// List.dropLast: List elem -> List elem
|
||||
fn list_drop_last(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
||||
let list_var = var_store.fresh();
|
||||
|
|
|
@ -1061,6 +1061,7 @@ define_builtins! {
|
|||
38 LIST_MAX: "max"
|
||||
39 LIST_MAX_GT: "#maxGt"
|
||||
40 LIST_MAP4: "map4"
|
||||
41 LIST_DROP_FIRST: "dropFirst"
|
||||
}
|
||||
5 RESULT: "Result" => {
|
||||
0 RESULT_RESULT: "Result" imported // the Result.Result type alias
|
||||
|
|
|
@ -267,6 +267,17 @@ fn list_drop_last_mutable() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_drop_first() {
|
||||
assert_evals_to!(
|
||||
"List.dropFirst [1, 2, 3]",
|
||||
RocList::from_slice(&[2, 3]),
|
||||
RocList<i64>
|
||||
);
|
||||
assert_evals_to!("List.dropFirst []", RocList::from_slice(&[]), RocList<i64>);
|
||||
assert_evals_to!("List.dropFirst [0]", RocList::from_slice(&[]), RocList<i64>);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_swap() {
|
||||
assert_evals_to!("List.swap [] 0 1", RocList::from_slice(&[]), RocList<i64>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue