mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 03:42:17 +00:00
Format List.roc
This commit is contained in:
parent
219e6d11cf
commit
fdbcbb74dd
1 changed files with 3 additions and 1 deletions
|
@ -380,6 +380,7 @@ walkHelp : List elem, state, (state, elem -> state), Nat, Nat -> state
|
||||||
walkHelp = \list, state, f, index, length ->
|
walkHelp = \list, state, f, index, length ->
|
||||||
if index < length then
|
if index < length then
|
||||||
nextState = f state (getUnsafe list index)
|
nextState = f state (getUnsafe list index)
|
||||||
|
|
||||||
walkHelp list nextState f (index + 1) length
|
walkHelp list nextState f (index + 1) length
|
||||||
else
|
else
|
||||||
state
|
state
|
||||||
|
@ -398,6 +399,7 @@ walkBackwardsHelp = \list, state, f, indexPlusOne ->
|
||||||
else
|
else
|
||||||
index = indexPlusOne - 1
|
index = indexPlusOne - 1
|
||||||
nextState = f state (getUnsafe list index)
|
nextState = f state (getUnsafe list index)
|
||||||
|
|
||||||
walkBackwardsHelp list nextState f index
|
walkBackwardsHelp list nextState f index
|
||||||
|
|
||||||
## Same as [List.walk], except you can stop walking early.
|
## 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.
|
## Some languages have a function called **`slice`** which works similarly to this.
|
||||||
sublist : List elem, { start : Nat, len : Nat } -> List elem
|
sublist : List elem, { start : Nat, len : Nat } -> List elem
|
||||||
|
|
||||||
|
|
||||||
## Intersperses `sep` between the elements of `list`
|
## Intersperses `sep` between the elements of `list`
|
||||||
## >>> List.intersperse 9 [1, 2, 3] # [1, 9, 2, 9, 3]
|
## >>> List.intersperse 9 [1, 2, 3] # [1, 9, 2, 9, 3]
|
||||||
intersperse : List elem, elem -> List elem
|
intersperse : List elem, elem -> List elem
|
||||||
|
@ -763,6 +764,7 @@ intersperse = \list, sep ->
|
||||||
capacity = Num.shiftLeftBy (List.len list) 1
|
capacity = Num.shiftLeftBy (List.len list) 1
|
||||||
init = List.withCapacity capacity
|
init = List.withCapacity capacity
|
||||||
newList = List.walk list init (\acc, elem -> acc |> List.append elem |> List.append sep)
|
newList = List.walk list init (\acc, elem -> acc |> List.append elem |> List.append sep)
|
||||||
|
|
||||||
List.dropLast newList
|
List.dropLast newList
|
||||||
|
|
||||||
## Splits the list into two lists, around the given index.
|
## Splits the list into two lists, around the given index.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue