From c9e83be7702f37e02ac96661c2a388c4f7d4060e Mon Sep 17 00:00:00 2001 From: Jonas Wanke Date: Thu, 12 Dec 2024 12:02:25 +0100 Subject: [PATCH] =?UTF-8?q?Add=20list.concat(=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages_v5/example.candy | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages_v5/example.candy b/packages_v5/example.candy index 01a111ca0..065c13fe1 100644 --- a/packages_v5/example.candy +++ b/packages_v5/example.candy @@ -411,6 +411,14 @@ fun replace[T](list: List[T], index: Int, item: T) List[T] { fun removeAt[T](list: List[T], index: Int) List[T] { builtinListRemoveAt(list, index) } +fun concat[T](list0: List[T], list1: List[T]) List[T] { + listGenerate(list0.length().add(list1.length()), (i: Int) { + switch i.isLessThan(list0.length()) { + true => list0.get(i).unwrap(), + false => list1.get(i.subtract(list0.length())).unwrap(), + } + }) +} fun getRange[T](list: List[T], startInclusive: Int, endExclusive: Int) List[T] { switch startInclusive.isNonNegative() .and(endExclusive.isNonNegative()) @@ -424,7 +432,7 @@ fun getRange[T](list: List[T], startInclusive: Int, endExclusive: Int) List[T] { } } -# TODO: .concatenate(…), .firstIndexWhere(…), .firstWhere(…), .firstIndexOf(…), .lastIndexWhere(…), .lastWhere(…), .lastIndexOf(…) +# TODO: .firstIndexWhere(…), .firstWhere(…), .firstIndexOf(…), .lastIndexWhere(…), .lastWhere(…), .lastIndexOf(…) fun print[T: ToText](t: T) { builtinPrint(t.toText()) }