- 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.NonEmpty¶
Type and functions for non-empty lists. This module re-exports many functions with
the same name as prelude list functions, so it is expected to import the module qualified.
For example, with the following import list you will have access to the NonEmpty
type
and any functions on non-empty lists will be qualified, for example as NE.append, NE.map, NE.foldl
:
import DA.NonEmpty (NonEmpty)
import qualified DA.NonEmpty as NE
Functions¶
- nonEmpty
: [a] -> Optional (NonEmpty a)
Turn a list into a non-empty list, if possible. Returns
None
if the input list is empty, andSome
otherwise.
- deleteBy
: (a -> a -> Bool) -> a -> NonEmpty a -> [a]
The ‘deleteBy’ function behaves like ‘delete’, but takes a user-supplied equality predicate.
- delete
: Eq a => a -> NonEmpty a -> [a]
Remove the first occurence of x from the non-empty list, potentially removing all elements.
- foldl1
: (a -> a -> a) -> NonEmpty a -> a
Apply a function repeatedly to pairs of elements from a non-empty list, from the left. For example,
foldl1 (+) (NonEmpty 1 [2,3,4]) = ((1 + 2) + 3) + 4
.
- foldr1
: (a -> a -> a) -> NonEmpty a -> a
Apply a function repeatedly to pairs of elements from a non-empty list, from the right. For example,
foldr1 (+) (NonEmpty 1 [2,3,4]) = 1 + (2 + (3 + 4))
.
- foldr
: (a -> b -> b) -> b -> NonEmpty a -> b
Apply a function repeatedly to pairs of elements from a non-empty list, from the right, with a given initial value. For example,
foldr (+) 0 (NonEmpty 1 [2,3,4]) = 1 + (2 + (3 + (4 + 0)))
.
- foldrA
: Action m => (a -> b -> m b) -> b -> NonEmpty a -> m b
The same as
foldr
but running an action each time.
- foldr1A
: Action m => (a -> a -> m a) -> NonEmpty a -> m a
The same as
foldr1
but running an action each time.
- foldl
: (b -> a -> b) -> b -> NonEmpty a -> b
Apply a function repeatedly to pairs of elements from a non-empty list, from the left, with a given initial value. For example,
foldl (+) 0 (NonEmpty 1 [2,3,4]) = (((0 + 1) + 2) + 3) + 4
.