mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
Implement List.takeFirst
This commit is contained in:
parent
978f9e0bc6
commit
878400f95f
13 changed files with 145 additions and 1 deletions
|
@ -12,7 +12,7 @@ use crate::llvm::build_list::{
|
|||
list_contains, list_drop, list_drop_at, list_get_unsafe, list_join, list_keep_errs,
|
||||
list_keep_if, list_keep_oks, list_len, list_map, list_map2, list_map3, list_map4,
|
||||
list_map_with_index, list_prepend, list_range, list_repeat, list_reverse, list_set,
|
||||
list_single, list_sort_with, list_swap,
|
||||
list_single, list_sort_with, list_swap, list_take_first,
|
||||
};
|
||||
use crate::llvm::build_str::{
|
||||
empty_str, str_concat, str_count_graphemes, str_ends_with, str_from_float, str_from_int,
|
||||
|
@ -5152,6 +5152,27 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
_ => unreachable!("Invalid layout {:?} in List.swap", list_layout),
|
||||
}
|
||||
}
|
||||
ListTakeFirst => {
|
||||
// List.takeFirst : List elem, Nat -> List elem
|
||||
debug_assert_eq!(args.len(), 2);
|
||||
|
||||
let (list, list_layout) = load_symbol_and_layout(scope, &args[0]);
|
||||
let original_wrapper = list.into_struct_value();
|
||||
|
||||
let count = load_symbol(scope, &args[1]);
|
||||
|
||||
match list_layout {
|
||||
Layout::Builtin(Builtin::EmptyList) => empty_list(env),
|
||||
Layout::Builtin(Builtin::List(element_layout)) => list_take_first(
|
||||
env,
|
||||
layout_ids,
|
||||
original_wrapper,
|
||||
count.into_int_value(),
|
||||
element_layout,
|
||||
),
|
||||
_ => unreachable!("Invalid layout {:?} in List.drop", list_layout),
|
||||
}
|
||||
}
|
||||
ListDrop => {
|
||||
// List.drop : List elem, Nat -> List elem
|
||||
debug_assert_eq!(args.len(), 2);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue