for more information visit the package's GitHub page
Package contains the following modules:
-r
/-l
foldr
, foldl
foldr
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 -0
How 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
, foldl
toChunksOf
instead of chunksFromLeft
/-Right
padToAtLeast
instead of resizerRepeat
, resizelRepeat
, resizerIndexed
, resizelIndexed
→ deal with both directions at once
```elm import Linear import Array exposing (Array) import Array.Linear
elementAlter : ( Linear.Direction, 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