{"id":349148,"date":"2023-06-21T15:02:36","date_gmt":"2023-06-21T15:02:36","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=349148"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=349148","title":{"rendered":"<span>\u041f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u043c \u0432 Scala: Magnolia<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 <a href=\"https:\/\/blog.michalp.net\/posts\/scala\/scala-derivations\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435<\/a> \u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u0432 Scala \u044f \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043b \u0441\u0443\u0442\u044c \u0438\u0434\u0435\u0438 \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0437 \u043d\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438. \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043a\u043e\u043f\u043d\u0435\u043c \u0433\u043b\u0443\u0431\u0436\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0434\u0435\u0440\u0438\u0432\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/softwaremill\/magnolia\">Magnolia<\/a>.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 Scala \u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e (intermediate) \u0443\u0440\u043e\u0432\u043d\u044f. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u043e\u0439, \u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043d\u0430\u0447\u0430\u0442\u044c \u0441 <a href=\"https:\/\/blog.michalp.net\/posts\/scala\/scala-derivations\/\">\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445<\/a>.<\/p>\n<h3>\u0420\u0435\u0437\u044e\u043c\u0435<\/h3>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b, \u0435\u0441\u043b\u0438 \u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043f\u043e\u0441\u0442, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0442\u0438\u043f\u0430 Show, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"scala\">trait Show[A] {   def show(a: A): String }<\/code><\/pre>\n<p>\u041c\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441 <code>Person<\/code>.<\/p>\n<pre><code class=\"scala\">object Show {    given Show[String] = new Show[String] {      def show(a: A): String   }    given Show[Int] = new Show[Int] {     def show(a: Int): String = a.toString()   }    extension [A: Show](a: A) {     def show: String = Show[A].show(a)    } }  val ShowPerson = new Show[Person] {   def show(a: Person): String =     s\"Person(name = ${a.name.show}, surname = ${a.surname.show}, age = ${a.age.show})\" }<\/code><\/pre>\n<p>\u0412\u0441\u043a\u043e\u0440\u0435 \u0441\u0442\u0430\u043b\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u0442\u0441\u044f\u00a0 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 show, \u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0441\u043f\u043e\u0441\u043e\u0431, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. \u041c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/typelevel\/kittens\">kittens<\/a>.<\/p>\n<h3>Magnolia<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u0438\u0437\u0443\u0447\u0438\u043c <a href=\"https:\/\/github.com\/softwaremill\/magnolia\">Magnolia<\/a> \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u0440\u0438\u0432\u0430\u0446\u0438\u044e Show \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Magnolia? \u0426\u0438\u0442\u0438\u0440\u0443\u044e \u0435\u0435 readme:<\/p>\n<p>Magnolia \u2014 \u044d\u0442\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u043a\u0440\u043e\u0441 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u043e\u0432) \u0438 \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439).\u00a0<\/p>\n<p>\u0417\u0432\u0443\u0447\u0438\u0442 \u0441\u043b\u043e\u0436\u043d\u043e? \u0421 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"scala\">object givens extends AutoDerivation[Show] {    \/\/ generate Show instance for case classes    override def join[T](caseClass: CaseClass[Show, T]): Show[T] = ???        \/\/ generate Show instance for sealed traits   override def split[T](sealedTrait: SealedTrait[Show, T]): Show[T] = ???  }<\/code><\/pre>\n<p><code>extends AutoDerivation[Show]<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e Magnolia \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0438\u043f\u0430 \u0434\u043b\u044f show, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044f, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 <code>join<\/code> \u0438 <code>split<\/code>.<\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 Show \u0434\u043b\u044f \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h3>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>join<\/code>, \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0432 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>CaseClass<\/code>:<\/p>\n<pre><code class=\"scala\">abstract class CaseClass[Typeclass[_], Type](     val typeInfo: TypeInfo,     val isObject: Boolean,     val isValueClass: Boolean,     val parameters: IArray[CaseClass.Param[Typeclass, Type]],     val annotations: IArray[Any],     val inheritedAnnotations: IArray[Any] = IArray.empty[Any],     val typeAnnotations: IArray[Any] )<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 <code>Show<\/code> \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438\u043c\u044f \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a name<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a <code>s\"${parameter.name} = ${Show.show(parameter.value)}<\/code>&#171;.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0438\u0445 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<\/li>\n<\/ol>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043c\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u043f\u043e\u043b\u0435 typeInfo, \u0435\u0433\u043e \u0442\u0438\u043f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a<\/p>\n<pre><code class=\"scala\">case class TypeInfo(     owner: String,     short: String,     typeParams: Iterable[TypeInfo] )<\/code><\/pre>\n<p>\u0418\u043c\u044f <code>short<\/code> \u2014 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u0449\u0435\u043c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>join<\/code><\/p>\n<pre><code class=\"scala\">override def join[T](caseClass: CaseClass[Show, T]): Show[T] =    new Show[T] {     def show(value: T) = {        val name = caseClass.typeInfo.short       val serializedParams = ???       s\"$name($serializedParams)\"     }   }<\/code><\/pre>\n<p>\u041c\u044b \u043f\u0440\u043e\u0448\u043b\u0438 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443 \u043f\u0443\u0442\u0438, \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 <code>serializedParam<\/code>. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0438\u0437 \u043f\u043e\u043b\u044f <code>parameters<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>CaseClass.Param<\/code><\/p>\n<pre><code class=\"scala\">trait Param[Typeclass[_], Type](     val label: String,     val index: Int,     val repeated: Boolean,     val annotations: IArray[Any],     val typeAnnotations: IArray[Any] )<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c, \u0438\u043c\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e, \u043e\u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432 \u043f\u043e\u043b\u0435 label. \u0410 \u043a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430? \u042d\u0442\u043e \u043d\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043b\u044f \u043f\u043e\u043b\u044f \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043d\u0435\u0442 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Param \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>deref<\/code>:<\/p>\n<pre><code class=\"scala\">\/**   * Get the value of this param out of the supplied instance of the case class.   *   * @param value an instance of the case class   * @return the value of this parameter in the case class   *\/ def deref(param: Type): PType<\/code><\/pre>\n<p>\u041f\u043e\u0445\u043e\u0436\u0435, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 param. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u044d\u0442\u0438\u043c API, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u0435\u043b \u0432 <code>serializedParams<\/code>:<\/p>\n<pre><code class=\"scala\">override def join[T](caseClass: CaseClass[Show, T]): Show[T] =    new Show[T] {     def show(value: T) = {        val name = caseClass.typeInfo.short       val serializedParams = caseClass.parameters.map { parameter =>         s\"${parameter.label} = ${parameter.typeclass.show(parameter.deref(value))}\"       }.mkString(\", \")       s\"$name($serializedParams)\"     }   }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435. \u041c\u044b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u043b\u0438 \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0442\u0440\u043e\u043a <code>key = value<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<\/p>\n<pre><code class=\"scala\">s\"${parameter.label} = ${parameter.typeclass.show(parameter.deref(value))}\"<\/code><\/pre>\n<p>\u0438 \u0437\u0430\u0442\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043b\u0438 \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>mkString<\/code>. \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043f\u043b\u0430\u043d \u0438\u0437 \u0442\u0440\u0435\u0445 \u043f\u0443\u043d\u043a\u0442\u043e\u0432, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435.<\/p>\n<p>\u0421\u043e <code>split<\/code> \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a <code>join<\/code>.<\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f Show \u0434\u043b\u044f \u0437\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043d\u044b\u0445 \u0442\u0440\u0435\u0439\u0442\u043e\u0432 \u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439<\/h3>\n<p>\u041c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443:<\/p>\n<pre><code class=\"scala\">override def split[T](sealedTrait: SealedTrait[Show, T]): Show[T] = ???<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0435\u0449\u0435 \u0440\u0430\u0437 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u044f <code>SealedTrait<\/code><\/p>\n<pre><code class=\"scala\">\/**  * Represents a Sealed-Trait or a Scala 3 Enum.  *  * In the terminology of Algebraic Data Types (ADTs), sealed-traits\/enums are termed  * 'sum types'.  *\/ case class SealedTrait[Typeclass[_], Type](     typeInfo: TypeInfo,     subtypes: IArray[SealedTrait.Subtype[Typeclass, Type, _]],     annotations: IArray[Any],     typeAnnotations: IArray[Any],     isEnum: Boolean,     inheritedAnnotations: IArray[Any] )<\/code><\/pre>\n<h3>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/h3>\n<p>\u0412\u0438\u0434\u0438\u043c \u0437\u0434\u0435\u0441\u044c \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0435 \u043b\u0438\u0446\u0430, \u0432\u0435\u0434\u044c \u043c\u044b \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 <code>typeInfo<\/code>. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u044f \u0441\u0434\u0435\u043b\u0430\u043b, \u0438\u0437\u0443\u0447\u0430\u044f Magnolia, \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b <code>split<\/code> \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"scala\">override def split[T](sealedTrait: SealedTrait[Show, T]): Show[T] =    sealedTrait.typeInfo.short<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u0435\u0441\u044c\u043c\u0430 \u0437\u0430\u043c\u0430\u043d\u0447\u0438\u0432\u043e \u0438 \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u041d\u043e \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u044f \u0442\u0440\u0435\u0439\u0442\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"scala\">enum Animal {   case Dog   case Cat   case Other(kind: String) }<\/code><\/pre>\n<p>\u0438 \u043c\u044b \u0431\u044b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u043b\u0438 \u0432\u044b\u0437\u043e\u0432 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u0433\u043e <code>Show<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"scala\">summon[Show[Animal]].show(Animal.Dog)<\/code><\/pre>\n<p>\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0431\u044b\u00a0 <code>Animal<\/code>, \u043a\u043e\u0433\u0434\u0430 \u043e\u0436\u0438\u0434\u0430\u043b\u0438 <code>Dog<\/code>.<\/p>\n<h3>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/h3>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u0441 \u043a\u0430\u043a\u0438\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0434\u0442\u0438\u043f\u043e\u043c \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u043d\u0430\u0440\u044f\u0434\u0443 \u0441 \u043f\u043e\u043b\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0443\u0436\u0435 \u0432\u0438\u0434\u0435\u043b\u0438, <code>SealedTrait<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>choose<\/code>:<\/p>\n<pre><code class=\"scala\">\/**   * Provides a way to recieve the type info for the explicit subtype that   * 'value' is an instance of. So if 'Type' is a Sealed Trait or Scala 3   * Enum like 'Suit', the 'handle' function will be supplied with the   * type info for the specific subtype of 'value', eg 'Diamonds'.   *   * @param value must be instance of a subtype of typeInfo   * @param handle function that will be passed the Subtype of 'value'   * @tparam Return whatever type the 'handle' function wants to return   * @return whatever the 'handle' function returned!   *\/ def choose[Return](value: Type)(handle: Subtype[_] => Return): Return <\/code><\/pre>\n<p>\u041e\u043d \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u0449\u0435\u043c \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u043e\u0434\u0442\u0438\u043f \u043d\u0430\u0448\u0435\u0433\u043e ADT (\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445). \u041a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 <code>handle<\/code>? \u041e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>show<\/code> \u043d\u0430 \u043f\u043e\u0434\u0442\u0438\u043f\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441, \u0438 <code>show<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c.<\/p>\n<p>\u0412 \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434\u0435 \u043c\u044b \u0438\u0449\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"scala\">sealedTrait.choose(value){ subtype =>    Show[subtype.Type].show(value) }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u0434\u0442\u0438\u043f\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>subtype.typeclass<\/code>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430\u0448\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439<\/p>\n<pre><code class=\"scala\">sealedTrait.choose(value){ subtype =>    subtype.typeclass.show(value) }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u044b\u0434\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<pre><code class=\"scala\">Found:    (value : T) Required: subtype.S &amp; T<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0438\u043f\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e ADT. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u043d\u0430\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0442\u0438\u043f\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>subtype.cast(value)<\/code><\/p>\n<pre><code class=\"scala\">sealedTrait.choose(value){ subtype =>    subtype.typeclass.show(subtype.cast(value)) }<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432\u043e\u0442 \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>join<\/code>, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0432 \u0442\u043e, \u0447\u0435\u043c\u0443 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c<\/p>\n<pre><code class=\"scala\">override def split[T](sealedTrait: SealedTrait[Show, T]): Show[T] =    new Show[T] {     def show(value: T): String =        sealedTrait.choose(value){ subtype =>          subtype.typeclass.show(subtype.cast(value))       }        }<\/code><\/pre>\n<h3>\u0421\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435 \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435<\/h3>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0448\u0438 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u0433\u043e\u0442\u043e\u0432\u044b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043c:<\/p>\n<pre><code class=\"scala\">import magnolia1.*  object Show {    object givens extends AutoDerivation[Show] {      given Show[String] = value => value     given [A](using Numeric[A]): Show[A] = _.toString      \/\/ generate Show instance for case classes      override def join[T](caseClass: CaseClass[Show, T]): Show[T] =        new Show[T] {         def show(value: T) = {            val name = caseClass.typeInfo.short           val serializedParams = caseClass.parameters.map { parameter =>             s\"${parameter.label} = ${parameter.typeclass.show(parameter.deref(value))}\"           }.mkString(\", \")           s\"$name($serializedParams)\"         }       }            \/\/ generate Show instance for sealed traits     override def split[T](sealedTrait: SealedTrait[Show, T]): Show[T] =        new Show[T] {         def show(value: T): String =            sealedTrait.choose(value){ subtype =>              subtype.typeclass.show(subtype.cast(value))           }                }    }  }<\/code><\/pre>\n<p>\u041d\u0430\u0440\u044f\u0434\u0443 \u0441 \u0434\u0432\u0443\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0434\u043b\u044f Magnolia, \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0433\u0438\u0432\u0435\u043d\u044b (\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b) \u0434\u043b\u044f <code>String<\/code> \u0438 <code>Numerics<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 \u043c\u0435\u0442\u043e\u0434 main \u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code class=\"scala\">case class MyCaseClass(number: Long, name: String) enum Animal {   case Dog   case Cat   case Other(kind: String) }  @main def main() = {   import Show.givens.given    println(     summon[Show[MyCaseClass]].show(MyCaseClass(number = 5, name = \"test\"))   )   println(     summon[Show[Animal]].show(Animal.Dog)   )   println(     summon[Show[Animal]].show(Animal.Other(\"snake\"))   )    }<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043c\u044b \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u044f\u0432\u043d\u0443\u044e \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e Show \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0442\u0438\u043f\u043e\u0432, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 <code>import Show.givens.given<\/code> \u0432\u0441\u0435 \u0443\u0436\u0435 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e.<\/p>\n<p>\u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"https:\/\/github.com\/majk-p\/derive-show-with-magnolia\">https:\/\/github.com\/majk-p\/derive-show-with-magnolia<\/a>.<\/p>\n<hr\/>\n<p>\u041a\u0430\u043a \u0441\u043a\u0440\u0435\u0441\u0442\u0438\u0442\u044c http4s \u0438 ZIO? \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0437\u0430\u0432\u0442\u0440\u0430 \u043d\u0430 <a href=\"https:\/\/otus.pw\/BPRp\/\">\u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u0443\u0440\u043e\u043a\u0435<\/a> \u0432 OTUS. \u041d\u0430 \u044d\u0442\u043e\u0439 \u0432\u0441\u0442\u0440\u0435\u0447\u0435 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p> \u0443\u0437\u043d\u0430\u0435\u043c o\u0431 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445 REST-\u0441\u0435\u0440\u0432\u0438\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e http4s (http-\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430) \u0438 ZIO (\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430);<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u0435\u043c\u0441\u044f \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e http-\u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u2014 \u0441\u0435\u0440\u0432\u0435\u0440, \u044d\u043d\u0434\u043f\u043e\u0438\u043d\u0442\u044b, \u043b\u043e\u0433\u0438\u043a\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u0423\u0440\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c \u0441\u043e Scala \u0438 \u0445\u043e\u0447\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u0437 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u0440\u043e\u043a \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/otus.pw\/BPRp\/\">\u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u0443\u0440\u0441\u0430 &#171;Scala-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a&#187;.<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/companies\/otus\/articles\/743094\/\"> https:\/\/habr.com\/ru\/companies\/otus\/articles\/743094\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 <a href=\"https:\/\/blog.michalp.net\/posts\/scala\/scala-derivations\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435<\/a> \u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u0432 Scala \u044f \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043b \u0441\u0443\u0442\u044c \u0438\u0434\u0435\u0438 \u0438 \u043f\u043e\u043a\u0430\u0437\u0430\u043b, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0437 \u043d\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0435, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438. \u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043a\u043e\u043f\u043d\u0435\u043c \u0433\u043b\u0443\u0431\u0436\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0434\u0435\u0440\u0438\u0432\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/github.com\/softwaremill\/magnolia\">Magnolia<\/a>.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u042d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 Scala \u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e (intermediate) \u0443\u0440\u043e\u0432\u043d\u044f. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u043e\u0439, \u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043d\u0430\u0447\u0430\u0442\u044c \u0441 <a href=\"https:\/\/blog.michalp.net\/posts\/scala\/scala-derivations\/\">\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445<\/a>.<\/p>\n<h3>\u0420\u0435\u0437\u044e\u043c\u0435<\/h3>\n<p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b, \u0435\u0441\u043b\u0438 \u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043f\u043e\u0441\u0442, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0442\u0438\u043f\u0430 Show, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"scala\">trait Show[A] {   def show(a: A): String }<\/code><\/pre>\n<p>\u041c\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441 <code>Person<\/code>.<\/p>\n<pre><code class=\"scala\">object Show {    given Show[String] = new Show[String] {      def show(a: A): String   }    given Show[Int] = new Show[Int] {     def show(a: Int): String = a.toString()   }    extension [A: Show](a: A) {     def show: String = Show[A].show(a)    } }  val ShowPerson = new Show[Person] {   def show(a: Person): String =     s\"Person(name = ${a.name.show}, surname = ${a.surname.show}, age = ${a.age.show})\" }<\/code><\/pre>\n<p>\u0412\u0441\u043a\u043e\u0440\u0435 \u0441\u0442\u0430\u043b\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u0442\u0441\u044f\u00a0 \u0448\u0430\u0431\u043b\u043e\u043d \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0439 show, \u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0441\u043f\u043e\u0441\u043e\u0431, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. \u041c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/github.com\/typelevel\/kittens\">kittens<\/a>.<\/p>\n<h3>Magnolia<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u0438\u0437\u0443\u0447\u0438\u043c <a href=\"https:\/\/github.com\/softwaremill\/magnolia\">Magnolia<\/a> \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0435\u0440\u0438\u0432\u0430\u0446\u0438\u044e Show \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Magnolia? \u0426\u0438\u0442\u0438\u0440\u0443\u044e \u0435\u0435 readme:<\/p>\n<p>Magnolia \u2014 \u044d\u0442\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u043a\u0440\u043e\u0441 \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0445 \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u043e\u0432) \u0438 \u0442\u0438\u043f\u043e\u0432 \u043a\u043e\u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439).\u00a0<\/p>\n<p>\u0417\u0432\u0443\u0447\u0438\u0442 \u0441\u043b\u043e\u0436\u043d\u043e? \u0421 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"scala\">object givens extends AutoDerivation[Show] {    \/\/ generate Show instance for case classes    override def join[T](caseClass: CaseClass[Show, T]): Show[T] = ???        \/\/ generate Show instance for sealed traits   override def split[T](sealedTrait: SealedTrait[Show, T]): Show[T] = ???  }<\/code><\/pre>\n<p><code>extends AutoDerivation[Show]<\/code> \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e Magnolia \u0434\u043e\u043b\u0436\u043d\u0430 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0438\u043f\u0430 \u0434\u043b\u044f show, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044f, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 <code>join<\/code> \u0438 <code>split<\/code>.<\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 Show \u0434\u043b\u044f \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/h3>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>join<\/code>, \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0432 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>CaseClass<\/code>:<\/p>\n<pre><code class=\"scala\">abstract class CaseClass[Typeclass[_], Type](     val typeInfo: TypeInfo,     val isObject: Boolean,     val isValueClass: Boolean,     val parameters: IArray[CaseClass.Param[Typeclass, Type]],     val annotations: IArray[Any],     val inheritedAnnotations: IArray[Any] = IArray.empty[Any],     val typeAnnotations: IArray[Any] )<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 <code>Show<\/code> \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0433\u043e \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0448\u0430\u0433\u0438:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438\u043c\u044f \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u043a\u0430\u043a name<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a <code>s\"${parameter.name} = ${Show.show(parameter.value)}<\/code>&#171;.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0438\u0445 \u0432 \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<\/li>\n<\/ol>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043c\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u0430, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u043f\u043e\u043b\u0435 typeInfo, \u0435\u0433\u043e \u0442\u0438\u043f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a<\/p>\n<pre><code class=\"scala\">case class TypeInfo(     owner: String,     short: String,     typeParams: Iterable[TypeInfo] )<\/code><\/pre>\n<p>\u0418\u043c\u044f <code>short<\/code> \u2014 \u044d\u0442\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u0449\u0435\u043c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>join<\/code><\/p>\n<pre><code class=\"scala\">override def join[T](caseClass: CaseClass[Show, T]): Show[T] =    new Show[T] {     def show(value: T) = {        val name = caseClass.typeInfo.short       val serializedParams = ???       s\"$name($serializedParams)\"     }   }<\/code><\/pre>\n<p>\u041c\u044b \u043f\u0440\u043e\u0448\u043b\u0438 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443 \u043f\u0443\u0442\u0438, \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0441 <code>serializedParam<\/code>. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0438\u0437 \u043f\u043e\u043b\u044f <code>parameters<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>CaseClass.Param<\/code><\/p>\n<pre><code class=\"scala\">trait Param[Typeclass[_], Type](     val label: String,     val index: Int,     val repeated: Boolean,     val annotations: IArray[Any],     val typeAnnotations: IArray[Any] )<\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c, \u0438\u043c\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e, \u043e\u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432 \u043f\u043e\u043b\u0435 label. \u0410 \u043a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430? \u042d\u0442\u043e \u043d\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043b\u044f \u043f\u043e\u043b\u044f \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0435\u0433\u043e \u043d\u0435\u0442 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 Param \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>deref<\/code>:<\/p>\n<pre><code class=\"scala\">\/**   * Get the value of this param out of the supplied instance of the case class.   *   * @param value an instance of the case class   * @return the value of this parameter in the case class   *\/ def deref(param: Type): PType<\/code><\/pre>\n<p>\u041f\u043e\u0445\u043e\u0436\u0435, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 param. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u044d\u0442\u0438\u043c API, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u0435\u043b \u0432 <code>serializedParams<\/code>:<\/p>\n<pre><code class=\"scala\">override def join[T](caseClass: CaseClass[Show, T]): Show[T] =    new Show[T] {     def show(value: T) = {        val name = caseClass.typeInfo.short       val serializedParams = caseClass.parameters.map { parameter =>         s\"${parameter.label} = ${parameter.typeclass.show(parameter.deref(value))}\"       }.mkString(\", \")       s\"$name($serializedParams)\"     }   }<\/code><\/pre>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0441\u0435. \u041c\u044b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u043b\u0438 \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0442\u0440\u043e\u043a <code>key = value<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e\u00a0<\/p>\n<pre><code class=\"scala\">s\"${parameter.label} = ${parameter.typeclass.show(parameter.deref(value))}\"<\/code><\/pre>\n<p>\u0438 \u0437\u0430\u0442\u0435\u043c \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043b\u0438 \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>mkString<\/code>. \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043f\u043b\u0430\u043d \u0438\u0437 \u0442\u0440\u0435\u0445 \u043f\u0443\u043d\u043a\u0442\u043e\u0432, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0448\u0435.<\/p>\n<p>\u0421\u043e <code>split<\/code> \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a <code>join<\/code>.<\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f Show \u0434\u043b\u044f \u0437\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043d\u044b\u0445 \u0442\u0440\u0435\u0439\u0442\u043e\u0432 \u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439<\/h3>\n<p>\u041c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u0438\u043c\u0435\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0443:<\/p>\n<pre><code class=\"scala\">override def split[T](sealedTrait: SealedTrait[Show, T]): Show[T] = ???<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0435\u0449\u0435 \u0440\u0430\u0437 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u044f <code>SealedTrait<\/code><\/p>\n<pre><code class=\"scala\">\/**  * Represents a Sealed-Trait or a Scala 3 Enum.  *  * In the terminology of Algebraic Data Types (ADTs), sealed-traits\/enums are termed  * 'sum types'.  *\/ case class SealedTrait[Typeclass[_], Type](     typeInfo: TypeInfo,     subtypes: IArray[SealedTrait.Subtype[Typeclass, Type, _]],     annotations: IArray[Any],     typeAnnotations: IArray[Any],     isEnum: Boolean,     inheritedAnnotations: IArray[Any] )<\/code><\/pre>\n<h3>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/h3>\n<p>\u0412\u0438\u0434\u0438\u043c \u0437\u0434\u0435\u0441\u044c \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0435 \u043b\u0438\u0446\u0430, \u0432\u0435\u0434\u044c \u043c\u044b \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 <code>typeInfo<\/code>. \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u044f \u0441\u0434\u0435\u043b\u0430\u043b, \u0438\u0437\u0443\u0447\u0430\u044f Magnolia, \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b <code>split<\/code> \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"scala\">override def split[T](sealedTrait: SealedTrait[Show, T]): Show[T] =    sealedTrait.typeInfo.short<\/code><\/pre>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u0435\u0441\u044c\u043c\u0430 \u0437\u0430\u043c\u0430\u043d\u0447\u0438\u0432\u043e \u0438 \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u041d\u043e \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u044f \u0442\u0440\u0435\u0439\u0442\u0430 \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0431\u044b \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"scala\">enum Animal {   case Dog   case Cat   case Other(kind: String) }<\/code><\/pre>\n<p>\u0438 \u043c\u044b \u0431\u044b \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u043b\u0438 \u0432\u044b\u0437\u043e\u0432 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u0433\u043e <code>Show<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"scala\">summon[Show[Animal]].show(Animal.Dog)<\/code><\/pre>\n<p>\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0431\u044b\u00a0 <code>Animal<\/code>, \u043a\u043e\u0433\u0434\u0430 \u043e\u0436\u0438\u0434\u0430\u043b\u0438 <code>Dog<\/code>.<\/p>\n<h3>\u041f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434<\/h3>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u0441 \u043a\u0430\u043a\u0438\u043c \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0434\u0442\u0438\u043f\u043e\u043c \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u043d\u0430\u0440\u044f\u0434\u0443 \u0441 \u043f\u043e\u043b\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0443\u0436\u0435 \u0432\u0438\u0434\u0435\u043b\u0438, <code>SealedTrait<\/code> \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>choose<\/code>:<\/p>\n<pre><code class=\"scala\">\/**   * Provides a way to recieve the type info for the explicit subtype that   * 'value' is an instance of. So if 'Type' is a Sealed Trait or Scala 3   * Enum like 'Suit', the 'handle' function will be supplied with the   * type info for the specific subtype of 'value', eg 'Diamonds'.   *   * @param value must be instance of a subtype of typeInfo   * @param handle function that will be passed the Subtype of 'value'   * @tparam Return whatever type the 'handle' function wants to return   * @return whatever the 'handle' function returned!   *\/ def choose[Return](value: Type)(handle: Subtype[_] => Return): Return <\/code><\/pre>\n<p>\u041e\u043d \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0438\u0449\u0435\u043c \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u043e\u0434\u0442\u0438\u043f \u043d\u0430\u0448\u0435\u0433\u043e ADT (\u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445). \u041a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430\u0448 \u043c\u0435\u0442\u043e\u0434 <code>handle<\/code>? \u041e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>show<\/code> \u043d\u0430 \u043f\u043e\u0434\u0442\u0438\u043f\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0435\u0439\u0441-\u043a\u043b\u0430\u0441\u0441, \u0438 <code>show<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c.<\/p>\n<p>\u0412 \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434\u0435 \u043c\u044b \u0438\u0449\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435:<\/p>\n<pre><code class=\"scala\">sealedTrait.choose(value){ subtype =>    Show[subtype.Type].show(value) }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u0434\u0442\u0438\u043f\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>subtype.typeclass<\/code>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043d\u0430\u0448\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a\u043e\u0439<\/p>\n<pre><code class=\"scala\">sealedTrait.choose(value){ subtype =>    subtype.typeclass.show(value) }<\/code><\/pre>\n<p>\u042d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u044b\u0434\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<pre><code class=\"scala\">Found:    (value : T) Required: subtype.S &amp; T<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0438\u043f\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e ADT. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u043d\u0430\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0442\u0438\u043f\u0443, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>subtype.cast(value)<\/code><\/p>\n<pre><code class=\"scala\">sealedTrait.choose(value){ subtype =>    subtype.typeclass.show(subtype.cast(value)) }<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432\u043e\u0442 \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <code>join<\/code>, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0432 \u0442\u043e, \u0447\u0435\u043c\u0443 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c<\/p>\n<pre><code class=\"scala\">override def split[T](sealedTrait: SealedTrait[Show, T]): Show[T] =    new Show[T] {     def show(value: T): String =        sealedTrait.choose(value){ subtype =>          subtype.typeclass.show(subtype.cast(value))       }        }<\/code><\/pre>\n<h3>\u0421\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u0435 \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435<\/h3>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0448\u0438 \u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u0433\u043e\u0442\u043e\u0432\u044b, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0445 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043c:<\/p>\n<pre><code class=\"scala\">import magnolia1.*  object Show {    object givens extends AutoDerivation[Show] {      given Show[String] = value => value     given [A](using Numeric[A]): Show[A] = _.toString      \/\/ generate Show instance for case classes      override def join[T](caseClass: CaseClass[Show, T]): Show[T] =        new Show[T] {         def show(value: T) = {            val name = caseClass.typeInfo.short           val serializedParams = caseClass.parameters.map { parameter =>             s\"${parameter.label} = ${parameter.typeclass.show(parameter.deref(value))}\"           }.mkString(\", \")           s\"$name($serializedParams)\"         }       }            \/\/ generate Show instance for sealed traits     override def split[T](sealedTrait: SealedTrait[Show, T]): Show[T] =        new Show[T] {         def show(value: T): String =            sealedTrait.choose(value){ subtype =>              subtype.typeclass.show(subtype.cast(value))           }                }    }  }<\/code><\/pre>\n<p>\u041d\u0430\u0440\u044f\u0434\u0443 \u0441 \u0434\u0432\u0443\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u0434\u043b\u044f Magnolia, \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0433\u0438\u0432\u0435\u043d\u044b (\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b) \u0434\u043b\u044f <code>String<\/code> \u0438 <code>Numerics<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-349148","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=349148"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/349148\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=349148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=349148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=349148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}