Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Random.generateTask #13

Open
Orasund opened this issue Nov 26, 2019 · 0 comments
Open

Feature Request: Random.generateTask #13

Orasund opened this issue Nov 26, 2019 · 0 comments

Comments

@Orasund
Copy link

Orasund commented Nov 26, 2019

I noticed that Elm/Random has no way to generate a random value as a Task. I’m not sure if this is intended.

Currently, I am trying to build a chat with Jsonstore at the backend.
If I now want to create a new chatroom, I need to first generate a number and then create the room.

createRoom : Task Error (Maybe Room)
createRoom =
    Random.generateTask Random.int 0 Random.maxInt
    |> Task.andThen insertNewRoom

sadly, Random has now task version of gernerate and therefore i need to instead split up the task into two messages.

update : Msg -> Model -> (Model,Cmd Msg)
update msg model =
    case msg of
        PressedNewRoomButton ->
            ( model
            , Random.generate Random.int 0 Random.maxInt
            )

        GeneratedRoomId int ->
            ( model
            , insertNewRoom int
                |> Task.attempt Sync
            )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant