fix to string for objects and either

This commit is contained in:
alexander.nutz
2024-03-28 18:34:38 +01:00
parent b87c0755ad
commit f9ddfcc4a7
2 changed files with 11 additions and 2 deletions

View File

@@ -38,8 +38,8 @@ class Either<A, B> private constructor(
Either(a, b.mapNotNull(transform))
override fun toString(): String =
if (isA) "Either<A>($a)"
else "Either<B>($b)"
if (isA) "Either<A>(${a!!.v})"
else "Either<B>(${b!!.v})"
companion object {
fun <A, B> ofA(a: A): Either<A, B> =

View File

@@ -9,6 +9,9 @@ interface Obj<T> {
fun <T> of(v: T): Obj<T> =
object : Obj<T> {
override val v: T = v
override fun toString(): String =
"Obj($v)"
}
}
}
@@ -26,6 +29,9 @@ interface MutObj<T> {
fun <T> of(v: T): MutObj<T> =
object : MutObj<T> {
override var v: T = v
override fun toString(): String =
"MutObj($v)"
}
fun <T> mutex(v: T): MutObj<T> =
@@ -34,6 +40,9 @@ interface MutObj<T> {
override var v: T = v
get() = lock.use { field }
set(inp) = lock.use { field = inp }
override fun toString(): String =
"MutMutexObj($v)"
}
}
}