jeudi 18 novembre 2021

Generate random UUIDv4 with Elm

I'm trying to generate random UUID's v4 within a loop:

    randomUuid =
         -- TODO: find a way to generate random uuid for variableId

    updatedVariables =              
         group.variables |> List.map (\variable -> { variable | id = randomUuid })

I read the doc of elm/random and elm/uuid but could not find how to generate an UUID without using a seed.

The only thing I could do is:

newUuid : Random.Seed -> ( String, Random.Seed )
newUuid seed =
    seed
        |> Random.step UUID.generator
        |> Tuple.mapFirst UUID.toString

I see that elm/random as an independentSeed function but I cannot get it to generate a seed.

The node equivalent of what I'm trying to achieve with randomUuid is:

const { uuid } = require('uuidv4');

const randomUuid = uuid();

I feel like I might be missing some important concept in Elm here but cannot figure that one on my own. Any help or pointer would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire