You mentioned my package Chadtech/return
as an inspiration. Thats really nice. And its really cool for me to see how someone else it taking on this problem, not only because these ideas are just interesting to consider but also because its implicitly feedback about my work on Chadtech/return
. So thank you for that.
I do have feedback below, and it looks like a lot of it is negative. Im sorry.
Also, I dont know if its possible, but I would love to collaborate towards a common tool; with you or anyone else interested in these problem. It doesnt have to be Chadtech/return
; I dont mind depreciating it. I just really like that theres often only one Elm package for any given use-case.
Common Ground
Im totally with you regarding fresheyeball/elm-return
being too haskelly, and janiczek/cmd-extra
just not having enough API. The API between your new package and Chadtech/return
have a lot of very similar functions so it seems like we are really close to a common understanding.
Uncommon Ground
I think the biggest break-iest difference we have is that I have had cases where I update the model
and pass on an a
in the same update (given your Step model msg a
type). An example use case would be a login page that in the same moment the user successfully logs in, it also changes to a success state, like the UI having a green border with the text “You have successfully logged in!”. Under that case in the update function you want to update the Login.Model
and return a User
simultaneously. I had a project where a majority of the OutMsg
also came with Cmd Msg
that weren’t just Cmd.none
. Returning a Cmd msg
and an a
or a Model
and an a
simultaneously doesnt look possible with your api. Am I wrong about that?
General Feedback
0 Names
Ive seen within
else-where with the name mapBoth
. I think thats a better name. To me, theres nothing particularly “within”-y about within
. I would say the same about to
, Step
and stay
. Maybe to
could be fromModel
. Regarding Step
, lots of things feel like steps, including decoding steps, validation steps, and view function steps. I would think the name should be more particular to the use case of update functions.
1 orElse
I think orElse
functions are cool and useful in many cases. However, in this case I see it as an anti-pattern. Its kind of weird to be generating multiple possible conclusions to your update, and then after the fact determining which conclusion to use using orElse
. Heres an alternative to your example for orElse
that has fewer lines, case statements, and let statements, and it doesnt involve this extra concept of ‘orElse’ (cool as orElse
may be, I always prefer fewer concepts to be at work).
case msg of
AddEvent e ->
Step.to { model | calendar = e :: model.calendar }
AddContact c ->
Step.to { model | contacts = c :: model.contacts }
_ ->
Step.stay