Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upIdea: Add an API to handle Random as a Task #924
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
process-bot
Dec 4, 2017
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
process-bot
commented
Dec 4, 2017
|
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it! Here is what to expect next, and if anyone wants to comment, keep these things in mind. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
sabiwara
Dec 4, 2017
(I opened the issue as recommended here: https://github.com/elm-lang/core/issues/322, but this is just an API idea, definitively not a bug. Sorry in advance if this is not the good place to post it!)
sabiwara
commented
Dec 4, 2017
|
(I opened the issue as recommended here: https://github.com/elm-lang/core/issues/322, but this is just an API idea, definitively not a bug. Sorry in advance if this is not the good place to post it!) |
sabiwara
changed the title from
Add an API to handle Random as a Task
to
Idea: Add an API to handle Random as a Task
Dec 4, 2017
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mkwiatkowski
Dec 4, 2017
@sabiwara There is already a way to generate numbers with a task: Random.step gen seed |> Task.succeed. You can combine those, but you will need to explicitly pass the seed from one step to another.
There was a discussion on Slack about this. I don't have a direct link, but here's what I have in my notes (quoting Ilias Van Peer):
The "issue" there is that you need to keep the seed in the model, which means that if you
perform(orattempt) a task using random generators, then fire off a second one before the first one resolves without the final result and the updated seed; they would use the same seed. One option there is to useindependentSeed(andRandom.Pcg), so you can give yourself an API where you first retrieve a new independent seed, store the updated seed in your model, and kick off the task-chain with that independent seed
- https://ellie-app.com/4BfPBPTVva1/0 <- demonstration of the problem (try clicking 3 times within 2 seconds, then see the value only update once)
- https://ellie-app.com/4BfPBPTVva1/1 <- and how to deal with it. Click all you want!
I hope this helps!
mkwiatkowski
commented
Dec 4, 2017
|
@sabiwara There is already a way to generate numbers with a task: There was a discussion on Slack about this. I don't have a direct link, but here's what I have in my notes (quoting Ilias Van Peer):
I hope this helps! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
sabiwara
Dec 4, 2017
Thanks for your prompt reply!
I didn't know about Random.Pcg, those examples will definitively help!
sabiwara
commented
Dec 4, 2017
|
Thanks for your prompt reply! |
evancz
added
the
request
label
Mar 7, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
klazuka
May 29, 2018
When considering this proposal, please also consider it in the light of UUID generation. I'm currently preparing a 20k LOC Elm app for 0.19 by removing the only "native" module in the codebase. That module exposed a single function, randomUuidTask : Task x String, which always succeeded with a new, random UUID. The app was modeled after elm-spa-example where each page's init returns a Task. I have 4 separate pages which need to be initialized with a random UUID and using a Task to generate the UUID composed nicely with other things that I need to do at page init time such as request data from the API server.
I'm trying to switch it over to use ports now but it's turning out to be a pretty invasive change and not nearly as clean as the old solution using the native task.
klazuka
commented
May 29, 2018
|
When considering this proposal, please also consider it in the light of UUID generation. I'm currently preparing a 20k LOC Elm app for 0.19 by removing the only "native" module in the codebase. That module exposed a single function, I'm trying to switch it over to use ports now but it's turning out to be a pretty invasive change and not nearly as clean as the old solution using the native task. |
sabiwara commentedDec 4, 2017
The
Randompackage does not expose any API to handle random generation as aTask, which makes simple composition of side effects difficult (e.g. sleep for a random amount of time, call an URL with some random parameter...).I saw this reddit thread mentioning something like a
Random.toTaskbut no opened issue for it.