alus-plugin_3.0.7.2.source-code.Data.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalus-plugin_3 Show documentation
Show all versions of scalus-plugin_3 Show documentation
Scalus - DApps Development Platform for Cardano
The newest version!
package scalus.builtin
import scala.collection.immutable
sealed abstract class Data
object Data extends DataApi:
type ToData[A] = A => Data
extension [A: ToData](a: A) inline def toData: Data = summon[ToData[A]](a)
extension (inline data: Data) inline def to[A](using inline ev: FromData[A]): A = ev(data)
type FromData[A] = Data => A
inline def fromData[A](inline data: Data)(using inline ev: FromData[A]): A = ev(data)
case class Constr(constr: Long, args: immutable.List[Data]) extends Data {
assert(constr >= 0, s"Constructor must be non-negative, got $constr")
}
case class Map(values: immutable.List[(Data, Data)]) extends Data {
override def hashCode(): Int = values.toSet.hashCode()
override def equals(x: Any): Boolean = x match {
case Map(otherValues) => values.toSet == otherValues.toSet
case _ => false
}
}
case class List(values: immutable.List[Data]) extends Data:
override def toString: String = s"List(${values.map(v => v.toString + "::").mkString}Nil)"
case class I(value: BigInt) extends Data
case class B(value: ByteString) extends Data:
override def toString: String = s"B(\"${value.toHex}\")"
val unit = Constr(0, immutable.Nil)