elm - Elm 中 Maybe a -> Svg Msg 类型的函数中没有 Nothing 时返回什么

标签 elm

我有一个函数可以将 Maybe Block 渲染为 Svg 矩形

type alias Block = {x:Int, y:Int}
type alias Prey = Maybe Block
renderPrey : Prey -> Svg Msg
renderPrey prey =
    case prey of
         Maybe.Just block -> --Svg rect  returns Svg msg
         Nothing -> -- how do I return something like Svg.none?

我看到没有 Svg.none http://package.elm-lang.org/packages/elm-lang/svg/2.0.0/Svg

我的解决方案是更改签名

renderPrey : Prey -> List(Svg Msg)
renderPrey prey =
    case prey of
         Maybe.Just block -> [--Svg rect  returns Svg msg]
         Nothing -> []

最佳答案

我使用Svg.text ""。到目前为止,我还没有遇到任何问题,但我还没有编写很多 SVG。

关于elm - Elm 中 Maybe a -> Svg Msg 类型的函数中没有 Nothing 时返回什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50195574/

相关文章:

json - 从 JSON 文件中读入数据

json - 递归解码嵌套列表(任意深度的列表的列表)

haskell - 代码在 Elm 中编译,但在 Haskell 中不编译

Elm onInput 字符后面一位

javascript - 为什么 Elm 0.19 中的 "remainderBy 0 100"返回 NaN,而不是 Maybe Int?

list - Elm 在更新列表中添加项目

types - 榆树中的类型继承

forms - 使用 Elm 提交表单而不跟踪字段值

elm - Elm 中的 `some_function` 构造是什么意思?

elm - if 语句导致类型错误 elm