DA.Foldable
文档索引
获取完整文档索引:https://docs.canton.network/llms.txt 在进一步浏览前,可用该文件发现所有可用页面。
DA.Foldable
Daml 模块 DA.Foldable 的参考文档。
DA.Foldable
可折叠为汇总值的数据结构类型类。
建议 qualified 导入本模块以免与 Prelude 中函数冲突,例如:
import DA.Foldable qualified as F
模块概览
类型类
class Foldable t
可折叠为汇总值的数据结构类型类。
方法:
fold : Monoid m => t m -> m用 monoid 合并结构中的元素。foldMap : Monoid m => (a -> m) -> t a -> m用 monoid 合并结构中的元素。foldr : (a -> b -> b) -> b -> t a -> b对结构做右结合 fold。foldl : (b -> a -> b) -> b -> t a -> b对结构做左结合 fold。foldr1 : (a -> a -> a) -> t a -> a无基情形的foldr变体,仅应用于非空结构。foldl1 : (a -> a -> a) -> t a -> a无基情形的foldl变体,仅应用于非空结构。toList : t a -> [a]结构的元素列表,从左到右。null : t a -> Bool判断结构是否为空。默认实现对类似 cons 列表的结构做了优化,因一般无法做得更好。length : t a -> Int以Int返回有限结构的大小/长度。默认实现对类似 cons 列表的结构做了优化。elem : Eq a => a -> t a -> Bool元素是否出现在结构中?sum : Additive a => t a -> a计算结构中数值的和。product : Multiplicative a => t a -> a计算结构中数值的积。minimum : Ord a => t a -> a非空结构的最小元素。maximum : Ord a => t a -> a非空结构的最大元素。
实例:
instance Ord k => Foldable (Map k)instance Foldable TextMapinstance Foldable Optionalinstance Foldable NonEmptyinstance Foldable Setinstance Foldable (Validation err)instance Foldable (Either a)instance Foldable []instance Foldable a
函数
mapA_
mapA_ : (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
将结构中每个元素映射为 action,从左到右求值并忽略结果。需要保留结果时请见 DA.Traversable.mapA。
forA_
forA_ : (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
forA_ 是参数翻转的 mapA_。需要保留结果时请见 DA.Traversable.forA。
forM_
forM_ : (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
sequence_
sequence_ : (Foldable t, Action m) => t (m a) -> m ()
从左到右求值结构中每个 action 并忽略结果。需要保留结果时请见 DA.Traversable.sequence。
concat
concat : Foldable t => t [a] -> [a]
拼接容器中所有列表元素。
and
and : Foldable t => t Bool -> Bool
and 返回 Bool 容器的合取。结果为 True 时容器须为有限;False 可由距左端有限距离处的 False 得出。
or
or : Foldable t => t Bool -> Bool
or 返回 Bool 容器的析取。结果为 False 时容器须为有限;True 可由距左端有限距离处的 True 得出。
any
any : Foldable t => (a -> Bool) -> t a -> Bool
判断结构中是否存在满足谓词的元素。
all
all : Foldable t => (a -> Bool) -> t a -> Bool
判断结构中是否所有元素都满足谓词。
本文由 CC Privacy Club 根据 Canton Network 官方文档(CC-BY-4.0)整理翻译,仅供学习;实现细节以官方最新版本为准。