From 6976d519c84dca691f84790affec6d7fc4121cb3 Mon Sep 17 00:00:00 2001 From: Simon Larsson Date: Sat, 26 Oct 2024 00:23:49 +0200 Subject: [PATCH] add/fix some stdlib functions --- luminapath/std/list/lib.lm | 4 ++++ luminapath/std/list/slice.lm | 2 +- luminapath/std/string/lib.lm | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/luminapath/std/list/lib.lm b/luminapath/std/list/lib.lm index e2774e2..7829a5e 100644 --- a/luminapath/std/list/lib.lm +++ b/luminapath/std/list/lib.lm @@ -125,6 +125,10 @@ pub fn take at list as uint, List a -> List a = let (lhs, rhs) = split_at at list in lhs +pub fn skip at list as uint, List a -> List a = + let (lhs, rhs) = split_at at list + in rhs + pub fn split_at at list as uint, List a -> (List a, List a) = if at == 0 then (Nil, list) diff --git a/luminapath/std/list/slice.lm b/luminapath/std/list/slice.lm index 8e97dc7..84a0e42 100644 --- a/luminapath/std/list/slice.lm +++ b/luminapath/std/list/slice.lm @@ -45,7 +45,7 @@ pub fn map f slice as fn(a -> b), Slice a -> Slice b = // Splits the slice at the given index. pub fn split_at at slice as uint, Slice a -> (Slice a, Slice a) = - (take at slice, skip (at+1) slice) + (take at slice, skip (at) slice) pub fn take n slice as uint, Slice a -> Slice a = { slice ~ len @ len = min n len } diff --git a/luminapath/std/string/lib.lm b/luminapath/std/string/lib.lm index 3f1c838..61c6d3f 100644 --- a/luminapath/std/string/lib.lm +++ b/luminapath/std/string/lib.lm @@ -41,6 +41,9 @@ impl Stringable for string pub fn break f str as fn(u8 -> bool), string -> (string, string) = Stringable:split_while str #f +pub fn skip n {inner} as uint, string -> string = + inner . list:skip n . fromBytes + pub fn fromByteVec vec as Vec u8 -> string = { string | inner = vec . to_slice . to_list }