liqwid-plutarch-extra-3.21.1: A collection of Plutarch extras from Liqwid Labs
Copyright(C) Liqwid Labs 2022
LicenseApache 2.0
MaintainerKoz Ross <[email protected]>
StabilityExperimental
PortabilityGHC only
Safe HaskellSafe-Inferred
LanguageHaskell2010

Plutarch.Extra.Ord

Description

Ordering-related helpers and functionality.

Synopsis

Types

data POrdering (s :: S) Source #

A representation of a comparison at the Plutarch level. Equivalent to Ordering in Haskell.

Since: 3.6.0

Constructors

PLT

Indicates a less-than relationship.

Since: 3.6.0

PEQ

Indicates equality.

Since: 3.6.0

PGT

Indicates a greater-than relationship.

Since: 3.6.0

Instances

Instances details
PEq POrdering Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

Methods

(#==) :: forall (s :: S). Term s POrdering -> Term s POrdering -> Term s PBool Source #

POrd POrdering Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

PPartialOrd POrdering Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

Methods

(#<=) :: forall (s :: S). Term s POrdering -> Term s POrdering -> Term s PBool Source #

(#<) :: forall (s :: S). Term s POrdering -> Term s POrdering -> Term s PBool Source #

PlutusType POrdering Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

Methods

pcon' :: forall (s :: S). POrdering s -> Term s (PInner POrdering) Source #

pmatch' :: forall (s :: S) (b :: PType). Term s (PInner POrdering) -> (POrdering s -> Term s b) -> Term s b Source #

PUnsafeLiftDecl POrdering Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

Associated Types

type PLifted POrdering = (r :: Type) Source #

PShow POrdering Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

Methods

pshow' :: forall (s :: S). Bool -> Term s POrdering -> Term s PString Source #

Generic (POrdering s) Source # 
Instance details

Defined in Plutarch.Extra.Ord

Associated Types

type Rep (POrdering s) :: Type -> Type Source #

Methods

from :: POrdering s -> Rep (POrdering s) x Source #

to :: Rep (POrdering s) x -> POrdering s Source #

Show (POrdering s) Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

Monoid (Term s POrdering) Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

Semigroup (Term s POrdering) Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

type PContravariant' POrdering Source # 
Instance details

Defined in Plutarch.Extra.Ord

type PContravariant' POrdering = All2 PContravariant'' (PCode POrdering)
type PCovariant' POrdering Source # 
Instance details

Defined in Plutarch.Extra.Ord

type PCovariant' POrdering = All2 PCovariant'' (PCode POrdering)
type PInner POrdering Source # 
Instance details

Defined in Plutarch.Extra.Ord

type PVariant' POrdering Source # 
Instance details

Defined in Plutarch.Extra.Ord

type PVariant' POrdering = All2 PVariant'' (PCode POrdering)
type PLifted POrdering Source # 
Instance details

Defined in Plutarch.Extra.Ord

type Rep (POrdering s) Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

type Rep (POrdering s) = D1 ('MetaData "POrdering" "Plutarch.Extra.Ord" "liqwid-plutarch-extra-3.21.1-KPadsMN5oqEA2Ctxwq6qig" 'False) (C1 ('MetaCons "PLT" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "PEQ" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "PGT" 'PrefixI 'False) (U1 :: Type -> Type)))

data PComparator (a :: S -> Type) (s :: S) Source #

Since: 3.6.0

Instances

Instances details
DerivePlutusType (PComparator a) Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

Associated Types

type DPTStrat (PComparator a) Source #

PlutusType (PComparator a) Source # 
Instance details

Defined in Plutarch.Extra.Ord

Methods

pcon' :: forall (s :: S). PComparator a s -> Term s (PInner (PComparator a)) Source #

pmatch' :: forall (s :: S) (b :: PType). Term s (PInner (PComparator a)) -> (PComparator a s -> Term s b) -> Term s b Source #

Generic (PComparator a s) Source # 
Instance details

Defined in Plutarch.Extra.Ord

Associated Types

type Rep (PComparator a s) :: Type -> Type Source #

Methods

from :: PComparator a s -> Rep (PComparator a s) x Source #

to :: Rep (PComparator a s) x -> PComparator a s Source #

type DPTStrat (PComparator a) Source # 
Instance details

Defined in Plutarch.Extra.Ord

type PContravariant' (PComparator a) Source # 
Instance details

Defined in Plutarch.Extra.Ord

type PContravariant' (PComparator a) = All2 PContravariant'' (PCode (PComparator a))
type PCovariant' (PComparator a) Source # 
Instance details

Defined in Plutarch.Extra.Ord

type PCovariant' (PComparator a) = All2 PCovariant'' (PCode (PComparator a))
type PInner (PComparator a) Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

type PVariant' (PComparator a) Source # 
Instance details

Defined in Plutarch.Extra.Ord

type PVariant' (PComparator a) = All2 PVariant'' (PCode (PComparator a))
type Rep (PComparator a s) Source #

Since: 3.6.0

Instance details

Defined in Plutarch.Extra.Ord

type Rep (PComparator a s) = D1 ('MetaData "PComparator" "Plutarch.Extra.Ord" "liqwid-plutarch-extra-3.21.1-KPadsMN5oqEA2Ctxwq6qig" 'False) (C1 ('MetaCons "PComparator" 'PrefixI 'True) (S1 ('MetaSel ('Just "pcomparatorEq") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Term s (a :--> (a :--> PBool)))) :*: S1 ('MetaSel ('Just "pcomparatorLe") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Term s (a :--> (a :--> PBool))))))

Functions

POrd functions

pmax :: forall (a :: S -> Type) (s :: S). POrd a => Term s (a :--> (a :--> a)) Source #

Return the maximum of two arguments.

Since: 3.15.4

pmin :: forall (a :: S -> Type) (s :: S). POrd a => Term s (a :--> (a :--> a)) Source #

Return the minimum of two arguments.

Since: 3.15.4

Creating comparators

pfromOrd :: forall (a :: S -> Type) (s :: S). POrd a => Term s (PComparator a) Source #

Given a type with a POrd instance, construct a PComparator from that instance.

Since: 3.6.0

pfromOrdBy :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). POrd a => Term s ((b :--> a) :--> PComparator b) Source #

As pfromOrd, but instead uses a projection function into the POrd instance to construct the PComparator. Allows other '-by' behaviours.

Since: 3.6.0

Transforming comparators

pmapComparator :: forall (a :: S -> Type) (b :: S -> Type) (s :: S). Term s ((b :--> a) :--> (PComparator a :--> PComparator b)) Source #

Given a projection from a type to another type which we have a PComparator for, construct a new PComparator.

Since: 3.6.0

preverseComparator :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> PComparator a) Source #

Reverses the ordering described by a PComparator.

Since: 3.6.0

Using comparators

Basic

pcompareBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> POrdering))) Source #

'Runs' a PComparator.

Since: 3.6.0

pequateBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool))) Source #

Uses a PComparator for an equality check.

Since: 3.6.0

pleqBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool))) Source #

Uses a PComparator for a less-than-or-equals check.

Since: 3.6.0

plessThanBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool))) Source #

Uses a PComparator for a less-than check.

Since: 3.9.0

pgeqBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool))) Source #

Uses a PComparator for a greater-than-or-equals check.

Since: 3.6.0

pgreaterThanBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> PBool))) Source #

Uses a PComparator for a greater-than check.

Since: 3.9.0

pmaxBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> a))) Source #

Uses a PComparator to return the maximum of two arguments

Since: 3.15.4

pminBy :: forall (a :: S -> Type) (s :: S). Term s (PComparator a :--> (a :--> (a :--> a))) Source #

Uses a PComparator to return the minimum of two arguments

Since: 3.15.4

Data structures

Map

pleqMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool))) Source #

Compares two sorted PMaps using a PComparator on their values. Specifically, this returns PTrue if, for any key in both argument PMaps, the value associated with this key in the first PMap compares less-than-or-equal-to its corresponding value in the second PMap; in any other case, this returns PFalse.

Since: 3.9.0

plessThanMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool))) Source #

As pleqMapBy, but the 'expected comparison' over values is strictly less than, rather than less-than-or-equal-to.

Since: 3.9.0

pgeqMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool))) Source #

As pleqMapBy, but the 'expected comparison' over values is greater-than-or-equal-to, rather than less-than-or-equal-to.

Since: 3.9.0

pgreaterThanMapBy :: forall (k :: S -> Type) (v :: S -> Type) (s :: S). (PIsData k, PIsData v, POrd k) => Term s (PComparator v :--> (PMap 'Sorted k v :--> (PMap 'Sorted k v :--> PBool))) Source #

As pleqMapBy, but the 'expected comparison' over values is strictly greater than, rather than less-than-or-equal-to.

Since: 3.9.0

PValue

pleqValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool))) Source #

Compares two PValues based on their 'inner map' pleqThanMapBy. More precisely, this returns PTrue if, for any PCurrencySymbol with a mapping in both PValues, their corresponding 'inner maps' all give PTrue using pleqMapBy with the given comparator.

Since: 3.9.0

plessThanValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool))) Source #

As pleqValueBy, except the 'comparison function' used is plessThanMapBy.

Since: 3.9.0

pgeqValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool))) Source #

As pleqValueBy, except the 'comparison function' used is pgeqMapBy.

Since: 3.9.0

pgreaterThanValueBy :: forall (amount :: AmountGuarantees) (s :: S). Term s (PComparator PInteger :--> (PValue 'Sorted amount :--> (PValue 'Sorted amount :--> PBool))) Source #

As pleqValueBy, except the 'comparison function' used is pgreaterThanMapBy.

Since: 3.9.0

Sortedness checking

pisSortedBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> PBool)) Source #

Verifies that a list-like structure is ordered according to the PComparator argument.

Since: 3.6.0

Uniqueness checking

pallUnique :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> PMaybe PBool) Source #

Verifies that a list-like structure is both ordered (by the POrd instance it's full of) and has no duplicates (by the PEq instance it's full of). This can give any of the following results:

  • PNothing if the structure is found to be unsorted;
  • PJust PFalse if the structure contains a duplicate; or
  • PJust PTrue if it is both sorted and contains no duplicates.

Since: 3.6.0

pallUniqueBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> PMaybe PBool)) Source #

As pallUnique, but using a custom PComparator to verify order and equality.

Since: 3.6.0

ptryAllUnique :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> PBool) Source #

As pallUnique, but errors if the list-like argument is found to be unsorted instead of returning PNothing.

Since: 3.6.0

ptryAllUniqueBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> PBool)) Source #

As pallUniqueBy, but errors if the list-like argument is found to be unsorted instead of returning PNothing.

Since: 3.6.0

Sorted merging

ptryMerge :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> (ell a :--> ell a)) Source #

Merge two list-like structures, whose contents are sorted by the POrd instance for their contents, into one sorted list-like structure. This will error if it finds that one of the list-like structures given to it as an argument is not sorted.

Since: 3.6.0

ptryMergeBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> (ell a :--> ell a))) Source #

As ptryMerge, but instead of using POrd to determine sorting, uses a custom PComparator. Will error out if one of the list-like structures given as an argument is not sorted according to the custom PComparator.

Since: 3.6.0

Sorting

psort :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> ell a) Source #

Sort a list-like by the POrd instance of its contents.

This uses a merge sort implementation, which is also stable. As this is a comparison sort, it requires a linearithmic ($n log(n)$) number of comparisons to complete.

Since: 3.6.0

psortBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> ell a)) Source #

As psort, but uses a custom PComparator for order comparisons.

Since: 3.6.0

Nubbing

pnubSort :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (POrd a, PElemConstraint ell a, PListLike ell) => Term s (ell a :--> ell a) Source #

As psort, but also throws out all duplicates according to the PEq instance of its argument's contents.

Since: 3.6.0

pnubSortBy :: forall (a :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PComparator a :--> (ell a :--> ell a)) Source #

As pnubSort, but uses a custom PComparator for both ordering and equality.

Since: 3.6.0

Inserting

pinsertUniqueBy :: forall (list :: PType -> PType) (a :: PType) (s :: S). PIsListLike list a => Term s (PComparator a :--> (a :--> (list a :--> list a))) Source #

Insert a value to a list with no duplicate, assuming the list is sorted in ascending order. Error out if the value is already in the list.

Since: 3.14.1

Orphan instances