-r/-lfoldr, foldlfoldr mean fold to the right? unclear and easy to mix upArray.getr/l, setr/l but foldr, foldl?Array.slice 0 -1 is handy! But you can't do slice 2 -0How about taking the Direction as an argument!
import Linear exposing (Direction(..))
import List.Linear
import Array exposing (Array)
import Array.Linear
[ 'l', 'i', 'v', 'e' ]
|> List.Linear.foldFrom "" Up String.cons
--> "evil"
[ 'l', 'i', 'v', 'e' ]
|> List.Linear.foldFrom "" Down String.cons
--> "live"
Array.fromList [ 'e', 'v', 'i', 'l' ]
|> Array.Linear.element ( Down, 0 )
--> Just 'l'→ a less cluttered API, e.g.
foldFrom instead of foldr, foldltoChunksOf instead of chunksFromLeft/-RightpadToLength instead of resizerRepeat, resizelRepeat, resizerIndexed, resizelIndexed→ deal with both directions at once
import Linear exposing (DirectionLinear)
import Array exposing (Array)
import Array.Linear
elementAlter :
( DirectionLinear, Int )
-> (element -> element)
-> (Array element -> Array element)
elementAlter location alter =
\array ->
case array |> Array.Linear.element location of
Nothing ->
array
Just elementAtLocation ->
array
|> Array.Linear.elementReplace location
(\() -> elementAtLocation |> alter)→ direction is always explicit
linear direction is already being used