完整文档页面(中文翻译)。文末附有来源说明。

阅读英文版

appdevreferencedaml-standard-libraryda-either

DA.Either

文档索引

获取完整文档索引:https://docs.canton.network/llms.txt 在进一步浏览前,可用该文件发现所有可用页面。

DA.Either

Daml 模块 DA.Either 的参考文档。

DA.Either

Either 类型表示具有两种可能性的值。

有时用于表示值要么正确、要么为错误。按惯例,Left 构造子存放错误值,Right 存放正确值(助记:「right」也有「正确」之意)。

模块概览

稳定。 Status: `active` Introduced in: `3.4.9` Removed in: `-` Warnings: `0` Deprecations: `0` Deprecated since: `-`

函数

lefts

lefts : [Either a b] -> [a]

从列表中提取所有 Left 元素。

rights

rights : [Either a b] -> [b]

从列表中提取所有 Right 元素。

partitionEithers

partitionEithers : [Either a b] -> ([a], [b])

Either 列表划分为两个列表,分别为 LeftRight 元素,并保持顺序。

isLeft

isLeft : Either a b -> Bool

若给定值为 Left,返回 True,否则返回 False

isRight

isRight : Either a b -> Bool

若给定值为 Right,返回 True,否则返回 False

fromLeft

fromLeft : a -> Either a b -> a

返回 Left 值的内容;若为 Right 则返回默认值。

fromRight

fromRight : b -> Either a b -> b

返回 Right 值的内容;若为 Left 则返回默认值。

optionalToEither

optionalToEither : a -> Optional b -> Either a b

Optional 转为 Either;若 OptionalNone,则使用所供参数作为 Left 值。

eitherToOptional

eitherToOptional : Either a b -> Optional b

Either 转为 Optional,丢弃 Left 中的值。

maybeToEither

maybeToEither : a -> Optional b -> Either a b

eitherToMaybe

eitherToMaybe : Either a b -> Optional b

本文由 CC Privacy Club 根据 Canton Network 官方文档(CC-BY-4.0)整理翻译,仅供学习;实现细节以官方最新版本为准。