Format List.roc

This commit is contained in:
Brian Carroll 2022-07-02 18:25:09 +01:00
parent 219e6d11cf
commit fdbcbb74dd
No known key found for this signature in database
GPG Key ID: 9CF4E3BF9C4722C7

View File

@ -380,6 +380,7 @@ walkHelp : List elem, state, (state, elem -> state), Nat, Nat -> state
walkHelp = \list, state, f, index, length ->
if index < length then
nextState = f state (getUnsafe list index)
walkHelp list nextState f (index + 1) length
else
state
@ -398,6 +399,7 @@ walkBackwardsHelp = \list, state, f, indexPlusOne ->
else
index = indexPlusOne - 1
nextState = f state (getUnsafe list index)
walkBackwardsHelp list nextState f index
## Same as [List.walk], except you can stop walking early.
@ -755,7 +757,6 @@ findIndex = \list, matcher ->
## Some languages have a function called **`slice`** which works similarly to this.
sublist : List elem, { start : Nat, len : Nat } -> List elem
## Intersperses `sep` between the elements of `list`
## >>> List.intersperse 9 [1, 2, 3] # [1, 9, 2, 9, 3]
intersperse : List elem, elem -> List elem
@ -763,6 +764,7 @@ intersperse = \list, sep ->
capacity = Num.shiftLeftBy (List.len list) 1
init = List.withCapacity capacity
newList = List.walk list init (\acc, elem -> acc |> List.append elem |> List.append sep)
List.dropLast newList
## Splits the list into two lists, around the given index.