That's substantially cleaner than my initial approach, and initial indications are that it'll work (i.e. it definitely compiles, but I need to test it out later). Thanks!
On Wednesday, October 19, 2016 at 2:03:13 PM UTC+2, Janis Voigtländer wrote: > > Why don’t you enrich your Msg type like so: > > type Msg = ... | Several (List Msg) > > and add a generic branch to your update function for processing a message > of the Several kind (something in the spirit of: update (Several msgs) = > List.foldr (... calling update recursively in an appropriate way ...) ... > msgs)? > > Then when you call Task.perform you make it generate a *single* Msg that > is a Several [msg1, msg2] value. That way, you do have the “production of > two messages” at the place you want it expressed. > > > 2016-10-19 13:51 GMT+02:00 Austin Bingham <[email protected] > <javascript:>>: > >> Yes, my current approach does seem pretty solid from a theoretical point >> of view, but it feels like a poor expression of my intent. I have to create >> this "synthetic" intermediate msg which only exists for the purposes of the >> recursion, and then I have to handle the production of two messages in a >> different part of the code (the update function) from where I really ask >> for them (the call to Task.perform). >> >> I guess what I'm getting hung up on is the fact that this is all >> necessitated by the design of Task.perform. What I'm trying to do may be so >> marginal that it doesn't make sense to try modifying Task.perform to >> accommodate it, and that's not really what I'm looking for anyway. I just >> wanted to see if there was some existing trick for doing a task-local >> expression of multiple msgs. >> >> On Wednesday, October 19, 2016 at 1:11:30 PM UTC+2, Simon wrote: >>> >>> Sounds like you a recursively apply the update function, and that sounds >>> like pretty solid functional programming >>> >>> >>> On Wednesday, 19 October 2016 11:51:16 UTC+2, Austin Bingham wrote: >>>> >>>> Is there a way to make Task.perform produce a batched "Cmd msg" on >>>> success (or failure, for that matter)? I've got a case where, on success, >>>> I >>>> want to send out more than one Msg, but because the success handler for >>>> Task.perform can only generate one msg this isn't straightforward. >>>> >>>> What I'm doing now is creating an intermediate msg from the success >>>> handler. When my update function handles this intermediate msg, it is then >>>> able to generate the batched Cmd of two msgs that I want. This seems to >>>> work well, but it feels like pattern that only exists because of >>>> Task.perform's design. >>>> >>>> So, is there a better way? Am I missing something that would let me >>>> remove this intermediate message, or is that just the way things have to >>>> work? >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Elm Discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
