Skip to content

Commit

Permalink
Allow registration of custom Show typeclasses #2021
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Jan 29, 2021
1 parent 445c554 commit 60374c7
Showing 1 changed file with 2 additions and 2 deletions.
Expand Up @@ -74,8 +74,8 @@ expect fun <A : Any> platformShow(a: A): Show<A>?
@Suppress("UNCHECKED_CAST")
fun <T : Any> commonShowFor(t: T): Show<T> {
// lookup a show from the registered typeclasses
val show = Shows.all().keys.firstOrNull { it.isInstance(t) }
if (show != null) return show as Show<T>
val kclass = Shows.all().keys.firstOrNull { it.isInstance(t) }
if (kclass != null) Shows.all()[kclass] as Show<T>
// this won't work in JS or native, so they'll get the boring old toString version
if (io.kotest.mpp.reflection.isDataClass(t::class)) return dataClassShow<T>()
return DefaultShow
Expand Down

0 comments on commit 60374c7

Please sign in to comment.