mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Merge branch 'trunk' into str_trim_left
This commit is contained in:
commit
07cd3850d7
62 changed files with 3288 additions and 7733 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,
|
||||
|
@ -1333,3 +1361,39 @@ inline fn listSetImmutable(
|
|||
//return list;
|
||||
return new_bytes;
|
||||
}
|
||||
|
||||
pub fn listFindUnsafe(
|
||||
list: RocList,
|
||||
caller: Caller1,
|
||||
data: Opaque,
|
||||
inc_n_data: IncN,
|
||||
data_is_owned: bool,
|
||||
alignment: u32,
|
||||
element_width: usize,
|
||||
inc: Inc,
|
||||
dec: Dec,
|
||||
) callconv(.C) extern struct { value: Opaque, found: bool } {
|
||||
if (list.bytes) |source_ptr| {
|
||||
const size = list.len();
|
||||
if (data_is_owned) {
|
||||
inc_n_data(data, size);
|
||||
}
|
||||
|
||||
var i: usize = 0;
|
||||
while (i < size) : (i += 1) {
|
||||
var theOne = false;
|
||||
const element = source_ptr + (i * element_width);
|
||||
inc(element);
|
||||
caller(data, element, @ptrCast(?[*]u8, &theOne));
|
||||
|
||||
if (theOne) {
|
||||
return .{ .value = element, .found = true };
|
||||
} else {
|
||||
dec(element);
|
||||
}
|
||||
}
|
||||
return .{ .value = null, .found = false };
|
||||
} else {
|
||||
return .{ .value = null, .found = false };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,12 +46,14 @@ 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");
|
||||
exportListFn(list.listSetInPlace, "set_in_place");
|
||||
exportListFn(list.listSwap, "swap");
|
||||
exportListFn(list.listAny, "any");
|
||||
exportListFn(list.listFindUnsafe, "find_unsafe");
|
||||
}
|
||||
|
||||
// Dict Module
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue