Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: elmcraft/core-extra
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.1.0
Choose a base ref
...
head repository: elmcraft/core-extra
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Oct 2, 2024

  1. Add Cmd.Extra.andThen (#66)

    * Add Cmd.Extra.andThen
    
    * elm-format
    Janiczek authored Oct 2, 2024
    Copy the full SHA
    e9e54c7 View commit details
Showing with 22 additions and 3 deletions.
  1. +1 −1 docs.json
  2. +21 −2 src/Cmd/Extra.elm
2 changes: 1 addition & 1 deletion docs.json

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions src/Cmd/Extra.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Cmd.Extra exposing
( perform, attempt, maybe, fromResult, fromMaybe
, pure, with, add, withTrigger, addTrigger, addIf, addTriggerMaybe, addMaybe
, pure, andThen, with, add, withTrigger, addTrigger, addIf, addTriggerMaybe, addMaybe
)

{-| Extra functions for working with Cmds.
@@ -13,7 +13,7 @@ module Cmd.Extra exposing
# Chaining in update
@docs pure, with, add, withTrigger, addTrigger, addIf, addTriggerMaybe, addMaybe
@docs pure, andThen, with, add, withTrigger, addTrigger, addIf, addTriggerMaybe, addMaybe
-}

@@ -138,6 +138,25 @@ pure model =
( model, Cmd.none )


{-| Allows chaining `update`-like functions.
sendNotification : Model -> (Model, Cmd Msg)
fireZeMissiles : Model -> (Model, Cmd Msg)
model
|> sendNotification -- we have (Model, Cmd Msg) now, but fireZeMissiles needs a Model
|> andThen fireZeMissiles
-}
andThen : (model1 -> ( model2, Cmd msg )) -> ( model1, Cmd msg ) -> ( model2, Cmd msg )
andThen fn ( model, cmd ) =
let
( newModel, newCmd ) =
fn model
in
( newModel, Cmd.batch [ cmd, newCmd ] )


{-| Add Cmd to model to create a pair.
-}
with : Cmd msg -> model -> ( model, Cmd msg )