Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lue-bird/elm-linear-direction
up or down a structure
https://github.com/lue-bird/elm-linear-direction
direction elm
Last synced: 25 days ago
JSON representation
up or down a structure
- Host: GitHub
- URL: https://github.com/lue-bird/elm-linear-direction
- Owner: lue-bird
- License: mit
- Created: 2021-04-05T16:25:34.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-28T08:41:13.000Z (over 1 year ago)
- Last Synced: 2024-12-09T18:02:06.263Z (about 1 month ago)
- Topics: direction, elm
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/lue-bird/elm-linear-direction/latest/
- Size: 226 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changes.md
- Contributing: contributing.md
- License: LICENSE
- Code of conduct: code_of_conduct.md
Awesome Lists containing this project
README
## [linear direction](https://dark.elm.dmy.fr/packages/lue-bird/elm-linear-direction/latest/)
- `-r`/`-l`
- for example: `foldr`, `foldl`
- does `foldr` mean fold to the right? unclear and easy to mix up
- no `Array.getr/l`, `setr/l` but `foldr`, `foldl`?
- negative indices
- `Array.slice 0 -1` is handy! But you can't do `slice 2 -0`
- many operations support negative indices, but others don't
- not explicit → can have unintended side-effectsHow about taking the **[`Direction`](Linear#Direction) as an argument**!
```elm
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`](https://package.elm-lang.org/packages/elm-community/list-split/latest/List-Split)
- `padToAtLeast` instead of `resizerRepeat`, `resizelRepeat`, `resizerIndexed`, `resizelIndexed`- → deal with both directions at once
```elm
import Linear
import Array exposing (Array)
import Array.LinearelementAlter :
( 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
## where `linear direction` is already being used
- [`emptiness-typed`](https://dark.elm.dmy.fr/packages/lue-bird/elm-emptiness-typed/latest/)
- [`typesafe-array`](https://dark.elm.dmy.fr/packages/lue-bird/elm-typesafe-array/latest/)
- [`keysset`](https://dark.elm.dmy.fr/packages/lue-bird/elm-keysset/latest/)
- [`rosetree-path`](https://dark.elm.dmy.fr/packages/lue-bird/elm-rosetree-path/latest/)## suggestions?
→ [contribute](https://github.com/lue-bird/elm-linear-direction/blob/master/contributing.md)