Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lue-bird/elm-bits
safe, typed bit arrays
https://github.com/lue-bird/elm-bits
array-sized bit elm safe type-safe typed typesafe-array vector
Last synced: 4 months ago
JSON representation
safe, typed bit arrays
- Host: GitHub
- URL: https://github.com/lue-bird/elm-bits
- Owner: lue-bird
- License: mit
- Created: 2021-05-03T07:59:13.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-18T08:34:20.000Z (6 months ago)
- Last Synced: 2024-09-29T08:04:59.764Z (4 months ago)
- Topics: array-sized, bit, elm, safe, type-safe, typed, typesafe-array, vector
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/lue-bird/elm-bits/latest/
- Size: 336 KB
- Stars: 0
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changes.md
- License: LICENSE
Awesome Lists containing this project
README
0, 1 and bit lists of sizes that don't have to be multiples of 8.
```elm
import Bit exposing (Bit(..))
import Bits-6 |> Bits.fromIntSigned 5
--> [ I, I, O, I, O ]
```Use when correctness/precision matters more than raw speed.
## example use case: id
Most id types use an opaque `type` to hold information.
Example similar to [danyx23's `Uuid`][danyx23/elm-uuid] to skim through ↓```elm
module OpaqueId exposing (OpaqueId, generate, toString)type OpaqueId
= OpaqueId StringtoString : OpaqueId -> String
toString =
\(OpaqueId string) -> stringgenerate : Random.Generator OpaqueId
generate =
Random.map
(\fifteenHexDigits ->
OpaqueId
([ fifteenHexDigits |> List.take 4 |> List.map mapToHex |> String.fromList
, "-"
, fifteenHexDigits |> List.drop 8 |> List.take 4 |> List.map mapToHex |> String.fromList
, "-"
, "4"
, fifteenHexDigits |> List.drop 12 |> List.take 2 |> List.map mapToHex |> String.fromList
, "-"
, fifteenHexDigits |> List.drop 14 |> List.take 1 |> List.map limitDigitRange8ToB |> List.map mapToHex |> String.fromList
]
|> String.concat
)
)
(Random.list 15 (Random.int 0 15))
```with bits:
```elm
module MyId exposing (MyId(..))import Bit exposing (Bit)
import Vector60type MyId
= MyId (Vector60 Bit) -- depending on necessary bits
```Notice how extracting information is easy and to creating a new id can be done safely (without e.g. requiring going through decoders, parsers, validations, opaque random generators etc.).
🧩 `Vector60` is from [Chadtech/elm-vector](https://dark.elm.dmy.fr/packages/Chadtech/elm-vector/latest)
but anything will do the job, like a record, custom codegen or [lue-bird/elm-typesafe-array](https://dark.elm.dmy.fr/packages/lue-bird/elm-typesafe-array/latest/).
Hell even if you just use an opaque `List Bit` you'll still have it easier than with a `String`.## conversions
Bits as a universal way of representing information can be
converted from and to basically any shape → [example](https://github.com/lue-bird/elm-bits/tree/master/example)- different string formats like human-readable (for example [michaelglass/proquint](https://package.elm-lang.org/packages/michaelglass/proquint/latest/)), less character space, hexadecimal, ...
- colors, shapes, identicons like
[coinop-logan/phace](https://package.elm-lang.org/packages/coinop-logan/phace/latest/),
[laurentpayot/minidenticons-elm](https://package.elm-lang.org/packages/laurentpayot/minidenticons-elm/latest/)
or forks of [pukkamustard/elm-identicon](https://github.com/pukkamustard/elm-identicon)
(like [dividat/elm-identicon](https://package.elm-lang.org/packages/dividat/elm-identicon/latest/)),
[`miniBill/elm-avataaars`](https://dark.elm.dmy.fr/packages/miniBill/elm-avataaars/latest/),
...## where `elm-bits` is used
- [`elm-morph`](https://package.elm-lang.org/packages/lue-bird/elm-morph/latest) can
create a parser-builder that can even read non-byte-multiple bit counts like 7
- maybe you built something? Tell me about it ✿----
Confused? Hyped? Hit @lue up on anything on slack
[danyx23/elm-uuid]: https://package.elm-lang.org/packages/danyx23/elm-uuid/latest/Uuid