Array library of the Chaos language. You can install this spell with:
occultist install array
and import it with:
import array
Merges list l1
and list l2
into a new list, in that order.
kaos> list a = [1, 2, 3]
kaos> list b = [4, 5, 6]
kaos> array.merge(a, b)
[1, 2, 3, 4, 5, 6]
Inserts a new item x
into list l
before index i
.
kaos> list a = [1, 2, 3]
kaos> array.insert(a, 5, 1)
[1, 5, 2, 3]
kaos> array.insert(a, 4)
[1, 2, 3, 4]
Reverse the order of items in the list l
.
kaos> import array
kaos> list a = [1, 2, 3]
kaos> array.reverse(a)
[3, 2, 1]
Chunk a list into x
length sublists.
kaos> import array
kaos> list c = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
kaos> array.chunk(c, 3)
[['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h']]
Searches the list haystack
for a given value needle
and returns the corresponding indexes if successful. Returns an empty list []
if unsuccessful.
kaos> list d = [1, 2, 3, 4, 5, 3, 6, 7, 3]
kaos> array.search(d, 3)
[2, 5, 8]
kaos> list e = ['foo', 'bar', 'foo', 'baz', 'bar', 'foo']
kaos> array.search(e, 'foo')
[0, 2, 5]
Replaces all occurrences of the needle
with the replacement
in list haystack
.
kaos> list d = [1, 2, 3, 4, 5, 3, 6, 7, 3]
kaos> list e = ['foo', 'bar', 'foo', 'baz', 'bar', 'foo']
kaos> array.replace(d, 3, 17)
[1, 2, 17, 4, 5, 17, 6, 7, 17]
kaos> array.replace(e, 'foo', 'goo')
['goo', 'bar', 'goo', 'baz', 'bar', 'goo']
Returns the length of list l
.
kaos> list a = [1, 2, 3]
kaos> array.length(a)
3