A typeclass that provides the number of inhabitants of common types.
- libarary for Scala 3 (JS, JVM, and Native platforms)
"com.julianpeeters" %% "typesize" % "0.1.0"
Calling SizeOf[A].size
returns an a Int
Cardinality
of three flavors:
Finite
: backed by aBigInt
NonFinite
: for types likeList[A]
TooBigToCompute
: for types likeString
Built-in typeclass instance are provided for common primitive and complex types, calculated by the following operations:
+
: take the sum of the members of a sealed trait*
: take the product of the members of a tuplepow
: take the exponentiation of the members of a function
import typesize.{Cardinality, SizeOf, given}
val c: Cardinality = summon[SizeOf[Option[Boolean]]].size
// c: Cardinality = Finite(i = 3)