Skip to content

Commit

Permalink
Add list.isEmpty(), .lastIndex()
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Nov 21, 2024
1 parent 1a174aa commit 9ec7bc2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages_v5/example.candy
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ struct List[T] = builtin
fun listFilled[T](length: Int, item: T) List[T] {
builtinListFilled(length, item)
}
# TODO: listGenerate(…)
fun listOf[T]() List[T] {
builtinListOf[T]()
}
Expand All @@ -137,6 +138,15 @@ fun listOf[T](item0: T, item1: T, item2: T, item3: T, item4: T) List[T] {
fun length[T](list: List[T]) Int {
builtinListLength(list)
}
fun isEmpty[T](list: List[T]) Bool {
list.length().equals(0)
}
fun lastIndex[T](list: List[T]) Maybe[Int] {
switch list.isEmpty() {
true => none[Int](),
false => some(list.length().subtract(1)),
}
}
fun get[T](list: List[T], index: Int) Maybe[T] {
builtinListGet(list, index)
}
Expand Down Expand Up @@ -164,11 +174,11 @@ fun append[T](list: List[T], item: T) List[T] {
fun replace[T](list: List[T], index: Int, item: T) List[T] {
builtinListReplace(list, index, item)
}
# TODO: list.update
# TODO: list.update(…)
fun removeAt[T](list: List[T], index: Int) List[T] {
builtinListRemoveAt(list, index)
}

# TODO: list.getRange(…), .concatenate(…), .firstIndexWhere(…), .firstWhere(…), .firstIndexOf(…), .lastIndexWhere(…), .lastWhere(…), .lastIndexOf(…)
fun print[T: ToText](t: T) {
builtinPrint(t.toText())
}
Expand Down

0 comments on commit 9ec7bc2

Please sign in to comment.