gulid
Types
Represents an opaque Ulid type.
Create
new(): Non-monotonic.new_monotonic(Ulid): Monotonic using previous.from_string(String): Parse ULID from a string.from_parts(Int, Int): Create from a timestamp milliseconds from Epoch and random.
Convert to String
let to_string = to_string_function()
let ulid = new()
io.println("Ulid: " <> to_string(ulid))
pub opaque type Ulid
Functions
pub fn from_bitarray(array: BitArray) -> Result(Ulid, UlidError)
Builds a Ulid value from given BitArray. Returns Ok with Ulid value
on success or UlidError otherwise.
pub fn from_parts(timestamp: Int, random: Int) -> Ulid
Returns Ulid value, build from given integer timestamp (millis from Epoch)
and random values
pub fn from_string_function() -> fn(String) ->
Result(Ulid, UlidError)
Returns a function that decodes a Ulid value from a given string. It
returns Ok with the Ulid value or UlidError.
Examples
let from_string = from_string_function()
let ulid_str = "01J9P2J2B0S4T4DFJAJ6RTV1DE"
let ulid = from_string(ulid_str)
io.debug(ulid)
pub fn from_tuple(parts: #(Int, Int)) -> Ulid
Returns Ulid value, build from given (timestamp, random) tuple.
pub fn new_as_string() -> String
Returns a non-monotonic ULID value as string. Note, this is a shortcut, not very good as far as the performance.
pub fn new_monotonic(prev_ulid: Ulid) -> Ulid
Returns new Ulid value based on given previous according to behavior,
described on ULID spec, basically, if previous has the same timestamp then
increment least significant bit of its random by 1 with carry to produce a
new Ulid (with the same timestamp).
pub fn to_parts(ulid: Ulid) -> #(Int, Int)
Returns an Ulid components #(timestamp: Int, random: Int) tuple.
pub fn to_string_function() -> fn(Ulid) -> String
Returns a function than converts a Ulid value to string.
Eamples
let to_string = to_string_function()
let ulid = new()
io.debug(to_string(ulid))