Q: Can direction be better expressed than in
foldr, foldl: does foldr mean fold right? A quite unclear nameArray.getr/l, setr/l but foldr, foldl?Array.slice 0 -1 is handy! But you can't do slice 2 -0A: Use the direction as an argument:
import LinearDirection exposing (LinearDirection(..))
import List.Linear
import Array exposing (Array)
import Array.Linear
[ 'l', 'i', 'v', 'e' ]
|> List.Linear.foldFrom "" FirstToLast String.cons
--> "evil"
[ 'l', 'i', 'v', 'e' ]
|> List.Linear.foldFrom "" LastToFirst String.cons
--> "live"
last : Array element -> Maybe element
last =
Array.Linear.at 0 LastToFirst→ a less cluttered API, e.g.
foldFrom instead of foldr, foldltoChunksOf instead of chunksFromLeft/-Right→ deal with both directions at once
import LinearDirection exposing (LinearDirection)
import Array exposing (Array)
import Array.Linear
alterAt :
Int -> LinearDirection -> (a -> a) -> Array a -> Array a
alterAt index direction alter =
\array ->
array
|> Array.Linear.replaceAt index direction
(array
|> Array.Linear.at index direction
|> alter
)→ direction is always explicit
→ See contributing.md