PairList

scalus.cardano.onchain.plutus.prelude.PairList
See thePairList companion object
enum PairList[+A, +B]

A list of key-value pairs that stays in the UPLC BuiltinPair representation, avoiding costly per-element conversions between PairData and ConstrData that occur when using List[(A, B)] with generic map/filter.

On JVM, PairList behaves like a regular list of tuples. On-chain, the compiler lowers it to the same SumDataPairList representation as List[(A, B)], so conversions via toList / toPairList are zero-cost (no UPLC code generated).

Pair-specific operations like mapValues operate directly on fstPair/sndPair builtins, yielding ~3x fewer builtin operations per element compared to List.map on tuples.

Type parameters

A

the type of the first element (key)

B

the type of the second element (value)

Attributes

Companion
object
Graph
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
class PairCons[A, B]

Members list

Type members

Enum entries

final case class PairCons[+A, +B](head: (A, B), tail: PairList[A, B]) extends PairList[A, B]
case PairNil extends PairList[Nothing, Nothing]

Value members

Concrete methods

def ++(other: PairList[A, B]): PairList[A, B]
Extension method from PairList
def asScala: List[(A, B)]
Extension method from PairList
def exists(p: ((A, B)) => Boolean): Boolean
Extension method from PairList
def filter(p: ((A, B)) => Boolean): PairList[A, B]
Extension method from PairList
def filterNot(p: ((A, B)) => Boolean): PairList[A, B]
Extension method from PairList
def find(p: ((A, B)) => Boolean): Option[(A, B)]
Extension method from PairList
def findMap[C](f: ((A, B)) => Option[C]): Option[C]
Extension method from PairList
def foldLeft[C](init: C)(f: (C, (A, B)) => C): C
Extension method from PairList
def foldRight[C](init: C)(f: ((A, B), C) => C): C
Extension method from PairList
def forall(p: ((A, B)) => Boolean): Boolean
Extension method from PairList
def head: (A, B)
Extension method from PairList

Returns the first element of this PairList.

Returns the first element of this PairList.

Attributes

Returns

The first key-value pair.

Throws
NoSuchElementException

If the PairList is empty.

Example
 PairList.single("a", 1).head === ("a", 1)
def isEmpty: Boolean
Extension method from PairList
def length: BigInt
Extension method from PairList
def map[C, D](f: ((A, B)) => (C, D)): PairList[C, D]
Extension method from PairList
def mapValues[C](f: B => C): PairList[A, C]
Extension method from PairList

Maps values while keeping keys unchanged.

Maps values while keeping keys unchanged.

On-chain this is significantly cheaper than List.map on tuples because it uses fstPair/sndPair builtins directly (~4 ops/element vs ~12).

Attributes

def nonEmpty: Boolean
Extension method from PairList
def prepended(elem: (A, B)): PairList[A, B]
Extension method from PairList
def toList: List[(A, B)]
Extension method from PairList

Converts this PairList to a List[(A, B)].

Converts this PairList to a List[(A, B)].

On-chain this is a zero-cost operation (noop in UPLC) because both types share the same SumDataPairList representation.

Attributes