如何在Test API模塊中的Cmd msg上進行模式匹配?如何在Test API模塊中的Cmd msg上模式匹配?
我有一個測試API用作Web服務的替代方案。
sources : Id -> (Result Http.Error (List Source) -> msg) -> Cmd msg
sources profileId msg =
[ { platform = "WordPress", username = "bizmonger", linksFound = 0 }
, { platform = "YouTube", username = "bizmonger", linksFound = 0 }
, { platform = "StackOverflow", username = "scott-nimrod", linksFound = 0 }
]
|> Result.Ok
|> msg
|> Task.succeed
|> Task.perform identity
問題:
我收到一個編譯錯誤代碼如下:
addSource : Id -> Source -> (Result Http.Error (List Source) -> msg) -> Cmd msg
addSource profileId source msg =
let
result =
sources profileId msg
in
case result of
Ok sources ->
(source :: sources)
|> Result.Ok
|> msg
|> Task.succeed
|> Task.perform identity
Err _ ->
Cmd.none
確定源 - > ^^^^^^^^^^圖案匹配東西類型:
Result error value
,但它實際上是想匹配的值是:
Cmd msg
注:
據我所知,這些函數返回一個cmd味精,我需要在一個cmd味精模式匹配。但是,此代碼位於TestAPI模塊中,而不是典型的UI模塊。因此,我認爲我不應該爲依賴於此TestAPI模塊的UI客戶端中已定義的各種消息定義區分聯合。
附錄:
type alias Source =
{ platform : String, username : String, linksFound : Int }
是啊..這就是我終於實現了。 –