make dropFirst and dropLast drop n elements

This commit is contained in:
Isaac Van Doren 2023-10-29 13:23:33 -05:00
parent cb6b36e218
commit 139d3c6f89
No known key found for this signature in database
GPG key ID: CFA524CD470E5B94
48 changed files with 3518 additions and 3470 deletions

View file

@ -329,7 +329,7 @@ fn decode() {
u8 = @MDecoder \lst, @Linear {} ->
when List.first lst is
Ok n -> { result: Ok n, rest: List.dropFirst lst }
Ok n -> { result: Ok n, rest: List.dropFirst lst 1 }
Err _ -> { result: Err TooShort, rest: [] }
MyU8 := U8 implements [MDecoding {decoder}]

View file

@ -521,19 +521,19 @@ fn list_chunks_of() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_drop() {
fn list_drop_first() {
assert_evals_to!(
"List.drop [1,2,3] 2",
"List.dropFirst [1,2,3] 2",
RocList::from_slice(&[3]),
RocList<i64>
);
assert_evals_to!(
"List.drop [] 1",
"List.dropFirst [] 1",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.drop [1,2] 5",
"List.dropFirst [1,2] 5",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
@ -703,18 +703,18 @@ fn list_drop_if_string_eq() {
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_drop_last() {
assert_evals_to!(
"List.dropLast [1, 2, 3]",
"List.dropLast [1, 2, 3] 1",
RocList::from_slice(&[1, 2]),
RocList<i64>
);
assert_evals_to!(
"List.dropLast []",
"List.dropLast [] 5",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.dropLast [0]",
RocList::<i64>::from_slice(&[]),
"List.dropLast [0] 0",
RocList::<i64>::from_slice(&[0]),
RocList<i64>
);
}
@ -728,7 +728,7 @@ fn list_drop_last_mutable() {
list : List I64
list = [if Bool.true then 4 else 4, 5, 6]
{ newList: List.dropLast list, original: list }
{ newList: List.dropLast list 1, original: list }
"#
),
(
@ -741,26 +741,6 @@ fn list_drop_last_mutable() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
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::<i64>::from_slice(&[]),
RocList<i64>
);
assert_evals_to!(
"List.dropFirst [0]",
RocList::<i64>::from_slice(&[]),
RocList<i64>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_swap() {

View file

@ -3006,7 +3006,7 @@ fn do_pass_bool_byte_closure_layout() {
any: Parser U8
any = \inp ->
when List.first inp is
Ok u -> [Pair u (List.drop inp 1)]
Ok u -> [Pair u (List.dropFirst inp 1)]
_ -> []