Coder Social home page Coder Social logo

elm-uuid's Introduction

Elm Uuid

This package provides an opaque type for Uuids, helpers to serialize from and to String and helpers to generate new Uuids using Elm's Random package.

Uuids are Universally Unique IDentifiers. They are 128 bit ids that are designed to be extremely unlikely to collide with other Uuids.

This library only supports generating Version 4 Uuid (those generated using random numbers, as opposed to hashing. See Wikipedia on Uuids for more details). Version 4 Uuids are constructed using 122 pseudo random bits.

Disclaimer: If you use this Library to generate Uuids, please be advised that it does not use a cryptographically secure pseudo random number generator. Depending on your use case the randomness provided may not be enough. The period of the underlying random generator is high, so creating lot's of random UUIDs on one client is fine, but please be aware that since the initial random seed of the current Random implementation is limited to 32 bits, creating UUIDs on many independent clients may lead to collisions more quickly than you think (see danyx23#10 for details)! If you need to generate UUIDs on many clients independently, please use the fork https://package.elm-lang.org/packages/Zinggi/elm-uuid/latest which covers this case.

This library is split into two Modules. Uuid wraps Uuids in an opaque type for improved type safety. If you prefer to simply get strings you can use the Uuid.Barebones module which provides methods to generate and verify Uuid as plain Strings.

Uuids can be generated either by parsing them from the canonical string representation (see fromString) or by generating them. If you are unfamiliar with random number generation in pure functional languages, this can be a bit confusing. The gist of it is that:

  1. you need a good random seed and this has to come from outside our wonderfully predictable Elm code (meaning you have to either use programWithFlags and pass in initial random seeds or alternatively use the Core.Random generate Cmd introduced with Elm 0.17 to get random values)

  2. every call to generate a new Uuid will give you a tuple of a Uuid and a new seed. It is very important that whenever you generate a new Uuid you store this seed you get back into your model and use this one for the next Uuid generation. If you reuse a seed, you will create the same Uuid twice!

Check out the example to see how this works in practice

Build Status

by Daniel Bachler

elm-uuid's People

Contributors

danyx23 avatar opsb avatar norpan avatar badri avatar waldheinz avatar rofrol avatar pukkamustard avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.