lue-bird/elm-bits/4.0.0

NOTE: the latest version is 10.1.1

Lue.Bits

Working with an Arr of Bits. To import as Bits

create

Nat (ArgIn minAmount maxAmount ifN_)
-> Generator (Arr (In minAmount maxAmount) Bit)

A Random.Generator for an Arr of Bits.

To use it effectively, you will need some extra bits of randomness.

transform

toNat : Arr (In minLength_ Nat53) Bit -> Nat (Min Nat0)

Convert an Arr of up to 53 Bits to a Nat.

Bits from the 53th index become mathematically unsound so they are avoided.

Bits.toNat (Arr.from8 I O O O I O I O)
--> Nat 138
Arr (In minLength_ maxLength_) Bit
-> Arr (Min Nat0) (Arr (In Nat8 (Nat8Plus a_)) Bit)

Group an Arr of Bits into Arrs of size 8.

Bits.toBytes (Arr.from1 O)
--> Arr.from1 (Arr.from8 O O O O O O O O)


Arr.from3 I I I
    |> InArr.append nat8 (Arr.from8 O I I I O I O O)
    |> InArr.append nat8 (Arr.from8 O I I I O I O O)
    |> InArr.append nat8 (Arr.from8 O I I I O I O O)
    |> Bits.toBytes
--> (Arr.from8 O O O O O I I I
-->     |> Arr.push (Arr.from8 O I I I O I O O)
-->     |> Arr.push (Arr.from8 O I I I O I O O)
-->     |> Arr.push (Arr.from8 O I I I O I O O)
--> )

Os at the start are kept.

padToByte : Arr (In min_ Nat8) Bit -> Arr (In Nat8 (Nat8Plus a_)) Bit

Fill Os to the begin of the Arr until it has 8 elements.

Arr.from3 I I I |> Bits.padToByte
--> Arr.from8 O O O O O I I I

extra

Nat (ArgIn minLength maxLength ifN_)
-> (Error -> error)
-> Codec error (Arr (In minLength maxLength) Bit)

A Codec for an Arr of Bits.

To get a Codec with a string error:

import Serialize exposing (Codec)

bit128 :
    Codec
        String
        (Arr (In Nat128 (Nat128Plus a_)) Bit)
bit128 =
    Bits.serialize nat128 Arr.errorToString

Use the serialize functions in InArr and MinArr to serialize Arrs with a length in a range.

 

Lue. is just the github username to avoid overlaps in module names.