Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rl-king/elm-index
A taggable wrapper around Int
https://github.com/rl-king/elm-index
array elm index list reorderable type
Last synced: about 1 month ago
JSON representation
A taggable wrapper around Int
- Host: GitHub
- URL: https://github.com/rl-king/elm-index
- Owner: rl-king
- License: bsd-3-clause
- Created: 2020-08-01T19:05:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-02T12:04:39.000Z (over 4 years ago)
- Last Synced: 2023-08-08T20:39:58.128Z (over 1 year ago)
- Topics: array, elm, index, list, reorderable, type
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/rl-king/elm-index/latest/
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-index
Disambiguate between different `Index` types by taggging `Index a`.
``` elm
-- With an anonymous record.
type alias RecordIndex =
Index { record : () }-- You could use some type you already have.
type BlockContent
= Text String
| Image Stringtype alias BlockIndex =
Index BlockContent-- Or, if you don't want to write `Index a` everywhere.
type alias Index =
Index ()```
Replace `Int` with the `Index a` type.
``` elm
example : List ( Index { example : () }, String )
example =
Index.indexedMap List.indexedMap
Tuple.pair
["hallo", "hola", "hello"]example : Array ( Index { example : () }, Int )
example =
Index.indexedMap Array.indexedMap
Tuple.pair
(Array.fromList [1, 2, 3])
```Make functions that expect an `Int` take an `Index a`.
``` elm
example : Index { example : () } -> Maybe Int
example index =
Index.withIndex Array.get index <|
Array.fromList [1, 2, 3]
```