mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Implement List.takeLast
This commit is contained in:
parent
35df58c18f
commit
772fc9c021
13 changed files with 142 additions and 1 deletions
|
@ -888,6 +888,34 @@ pub fn listTakeFirst(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn listTakeLast(
|
||||
list: RocList,
|
||||
alignment: u32,
|
||||
element_width: usize,
|
||||
take_count: usize,
|
||||
dec: Dec,
|
||||
) callconv(.C) RocList {
|
||||
if (take_count == 0) {
|
||||
return RocList.empty();
|
||||
}
|
||||
if (list.bytes) |source_ptr| {
|
||||
const size = list.len();
|
||||
if (size <= take_count) {
|
||||
return list;
|
||||
}
|
||||
const drop_count = size - take_count;
|
||||
return listDrop(
|
||||
list,
|
||||
alignment,
|
||||
element_width,
|
||||
drop_count,
|
||||
dec,
|
||||
);
|
||||
} else {
|
||||
return RocList.empty();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn listDrop(
|
||||
list: RocList,
|
||||
alignment: u32,
|
||||
|
|
|
@ -46,6 +46,7 @@ comptime {
|
|||
exportListFn(list.listSortWith, "sort_with");
|
||||
exportListFn(list.listConcat, "concat");
|
||||
exportListFn(list.listTakeFirst, "take_first");
|
||||
exportListFn(list.listTakeLast, "take_last");
|
||||
exportListFn(list.listDrop, "drop");
|
||||
exportListFn(list.listDropAt, "drop_at");
|
||||
exportListFn(list.listSet, "set");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue