Devs.tw 是讓工程師寫筆記、網誌的平台。歡迎您隨手紀錄、寫作,方便日後搜尋!
Cmd.batch
[ Task.succeed GenerateNewUuid |> Task.perform identity
, Task.succeed GenerateNewUuid |> Task.perform identity
, Task.succeed GenerateNewUuid |> Task.perform identity
, Task.succeed GenerateNewUuid |> Task.perform identity
]
Cmd.batch
[ send GenerateNewUuid
, send GenerateNewUuid
, send GenerateNewUuid
, send GenerateNewUuid
]
send : msg -> Cmd msg
send msg =
Task.perform identity (Task.succeed msg)
import Random
import Random.Int
前者是內建的
後者需要 elm install elm-community/random-extra
設計哲學為何
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
MoveReviewColumnUp index ->
( { model | reviewColumns = List.Extra.swapAt index (index - 1) model.reviewColumns }, Cmd.none )
MoveReviewColumnDown index ->
( { model | reviewColumns = List.Extra.swapAt index (index + 1) model.reviewColumns }, Cmd.none )
DeleteReviewColumn index ->
( { model | reviewColumns = List.Extra.removeAt index model.reviewColumns }, Cmd.none )
getInfoType : String -> InfoType
getInfoType value =
case value of
"text" ->
Text
"address" ->
Address
"city" ->
City
The technique of using pattern matching to to implement logic in your code is a very standard technique in functional programming. In some sense it is a very natural way to have different code to handle different patterns. There are quite a few different things that you can use as patterns:
moreInfo column =
reviewColumnsView model =
The first one doesn’t produce any events, so its type variable is not bound to anything yet. The second one produces events of your Msg type, and its type variable is bound to that.
ref: https://discourse.elm-lang.org/t/html-msg-vs-html-msg/2758
google: Html msg vs Html Msg elm