mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 16:51:53 +03:00
Format List.roc
This commit is contained in:
parent
219e6d11cf
commit
fdbcbb74dd
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user