尤川豪   ·  1年前
445 貼文  ·  275 留言

FP ... Elm ... 筆記

乍看之下 連 json decoder 都是一種 ... promise ...??

也就是要處理 success / fail 兩種結果

ratingsDecoder : Json.Decode.Decoder (List RatingColumn)
ratingsDecoder =
    Json.Decode.list ratingDecoder

decodeRatings : String -> List RatingColumn
decodeRatings str =
    case Json.Decode.decodeString ratingsDecoder str of
        Ok ratings ->
            ratings

        Err _ ->
            []

Ajax 也是這樣處理的

在 FP 領域 Maybe 也是這樣處理 nullable 的

這術語叫什麼?

  分享   共 487 次點閱
共有 1 則留言
尤川豪   ·  1年前
445 貼文  ·  275 留言

Pretty much anything that uses I/O is impure. The data in the DB could change, the request could fail, so it doesn't give any reliable guarantee that it will return consistent values.

反正,就是一些 IO 相關

impure 的部份

一律使用這種有 success/error 的寫法

 
您的留言
尤川豪
445 貼文  ·  275 留言

Devs.tw 是讓工程師寫筆記、網誌的平台。隨手紀錄、寫作,方便日後搜尋!

歡迎您一起加入寫作與分享的行列!

查看所有文章