- Overview
- Tutorials
- Getting started
- Get started with Canton and the JSON Ledger API
- Get Started with Canton, the JSON Ledger API, and TypeScript
- Get started with Canton Network App Dev Quickstart
- Get started with smart contract development
- Basic contracts
- Test templates using Daml scripts
- Build the Daml Archive (.dar) file
- Data types
- Transform contracts using choices
- Add constraints to a contract
- Parties and authority
- Compose choices
- Handle exceptions
- Work with dependencies
- Functional programming 101
- The Daml standard library
- Test Daml contracts
- Next steps
- Application development
- Getting started
- Development how-tos
- Component how-tos
- Explanations
- References
- Application development
- Smart contract development
- Daml language cheat sheet
- Daml language reference
- Daml standard library
- DA.Action.State.Class
- DA.Action.State
- DA.Action
- DA.Assert
- DA.Bifunctor
- DA.Crypto.Text
- DA.Date
- DA.Either
- DA.Exception
- DA.Fail
- DA.Foldable
- DA.Functor
- DA.Internal.Interface.AnyView.Types
- DA.Internal.Interface.AnyView
- DA.List.BuiltinOrder
- DA.List.Total
- DA.List
- DA.Logic
- DA.Map
- DA.Math
- DA.Monoid
- DA.NonEmpty.Types
- DA.NonEmpty
- DA.Numeric
- DA.Optional
- DA.Record
- DA.Semigroup
- DA.Set
- DA.Stack
- DA.Text
- DA.TextMap
- DA.Time
- DA.Traversable
- DA.Tuple
- DA.Validation
- GHC.Show.Text
- GHC.Tuple.Check
- Prelude
- Smart contract upgrading reference
- Glossary of concepts
DA.Foldable¶
Class of data structures that can be folded to a summary value.
It’s a good idea to import this module qualified to avoid clashes with
functions defined in Prelude
. Ie.:
import DA.Foldable qualified as F
Typeclasses¶
class Foldable t where
Class of data structures that can be folded to a summary value.
- foldr
: (a -> b -> b) -> b -> t a -> b
Right-associative fold of a structure.
- foldl
: (b -> a -> b) -> b -> t a -> b
Left-associative fold of a structure.
- foldr1
: (a -> a -> a) -> t a -> a
A variant of foldr that has no base case, and thus should only be applied to non-empty structures.
- foldl1
: (a -> a -> a) -> t a -> a
A variant of foldl that has no base case, and thus should only be applied to non-empty structures.
- toList
: t a -> [a]
List of elements of a structure, from left to right.
- null
: t a -> Bool
Test whether the structure is empty. The default implementation is optimized for structures that are similar to cons-lists, because there is no general way to do better.
- length
: t a -> Int
Returns the size/length of a finite structure as an
Int
. The default implementation is optimized for structures that are similar to cons-lists, because there is no general way to do better.
- product
: Multiplicative a => t a -> a
The product function computes the product of the numbers of a structure.
instance Ord k => Foldable (Map k)
instance Foldable (Validation err)
instance Foldable a
Functions¶
- mapA_
: (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
Map each element of a structure to an action, evaluate these actions from left to right, and ignore the results. For a version that doesn’t ignore the results see ‘DA.Traversable.mapA’.
- forA_
: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
‘for_’ is ‘mapA_’ with its arguments flipped. For a version that doesn’t ignore the results see ‘DA.Traversable.forA’.
- forM_
: (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
- sequence_
: (Foldable t, Action m) => t (m a) -> m ()
Evaluate each action in the structure from left to right, and ignore the results. For a version that doesn’t ignore the results see ‘DA.Traversable.sequence’.
- and
: Foldable t => t Bool -> Bool
and
returns the conjunction of a container of Bools. For the result to beTrue
, the container must be finite;False
, however, results from aFalse
value finitely far from the left end.
- or
: Foldable t => t Bool -> Bool
or
returns the disjunction of a container of Bools. For the result to beFalse
, the container must be finite;True
, however, results from aTrue
value finitely far from the left end.