+lines, -lines, +best practice avoid access by index
This commit is contained in:
parent
2ed0b1ed14
commit
a1a0465a3d
|
@ -1,11 +1,13 @@
|
|||
# List
|
||||
|
||||
Aiken lists are plutus linked lists. Accessing by index is O(n). Appending or accessing head is O(1). Grabbing tail is O(1).
|
||||
Aiken lists are plutus linked lists.
|
||||
Accessing by index is O(n).
|
||||
Appending or accessing head is O(1).
|
||||
Grabbing tail is O(1).
|
||||
|
||||
There is no builtin syntax for accessing by index as this is implemented by standard libs.
|
||||
|
||||
Accessing head, tail, or preceding elements can be done by pattern matching.
|
||||
|
||||
```gleam
|
||||
// this function checks if a list has a sequence of 1 then 2 contained within it.
|
||||
fn listStuff(a: List(Int)){
|
||||
|
@ -18,4 +20,6 @@ fn listStuff(a: List(Int)){
|
|||
```
|
||||
|
||||
Helper functions for safely accessing head, tail, are provided in standard lib but are implemented using comprehensions.
|
||||
It is usually best to use your own comprehensions for efficiency (until the optimiser is better).
|
||||
It is usually best to use your own comprehensions for efficiency (until the optimiser is better).
|
||||
|
||||
It is best to avoid accesses by indexes if possible for efficiency.
|
Loading…
Reference in New Issue