snowflake- A loose port of Twitter Snowflake to Haskell. Generates arbitrary precision, unique, time-sortable identifiers.

LicenseApache 2.0
Safe HaskellSafe-Inferred



This generates unique(guaranteed) identifiers build from time stamp, counter(inside same millisecond) and node id - if you wish to generate ids across several nodes. Identifiers are convertible to Integer values which are monotonically increasing with respect to time.



data SnowflakeConfig Source

Configuration that specifies how much bits are used for each part of the id. There are no limits to total bit sum.



data Snowflake Source

Generated identifier. Can be converted to Integer.

data SnowflakeGen Source

Generator which contains needed state. You should use newSnowflakeGen to create instances.

newSnowflakeGen :: SnowflakeConfig -> Integer -> IO SnowflakeGen Source

Create a new generator. Takes a configuration and node id.

nextSnowflake :: SnowflakeGen -> IO Snowflake Source

Generates next id. The bread and butter. See module description for details.

defaultConfig :: SnowflakeConfig Source

Default configuration using 40 bits for time, 16 for count and 8 for node id.

snowflakeToInteger :: Snowflake -> Integer Source

Converts an identifier to an integer with respect to configuration used to generate it.