Skip to content

Commit

Permalink
Add list.concat(…)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Dec 12, 2024
1 parent ee7055c commit c9e83be
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages_v5/example.candy
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
}
Expand Down

0 comments on commit c9e83be

Please sign in to comment.