Hata türü toplama için shapeless 'Coproduct kullanmaya çalışıyorum. Kendimi tekrarlamak zorunda kalmadanTip bildirimlerini genişletmenin bir yolu var mı?
import shapeless._
case object F1
case object F2
type F12 = F1.type :+: F2.type :+: CNil
case object F3
case object F4
type F34 = F3.type :+: F4.type :+: CNil
type F1234 = F1.type :+: F2.type :+: F3.type :+: F4.type :+: CNil
def custom(f: Either[F12, F34]): F1234 = // how can I declare the resulting type?
f.fold(_.extendRightBy[F34], _.extendLeftBy[F12])
object F1234Handler extends Poly1 {
implicit def caseF1 = at[F1.type](_ => "got F1")
implicit def caseF2 = at[F2.type](_ => "got F2")
implicit def caseF3 = at[F3.type](_ => "got F3")
implicit def caseF4 = at[F4.type](_ => "got F4")
}
custom(Left(Coproduct[F12](F2))).fold(F1234Handler) // got F2
Nasıl özel kat sonuç tanımlayabilir: Aşağıdaki Şu anda var sorunu yalıtmak için bir girişimdir? İdeal olarak, F1234'ü benim yaptığım şekilde beyan etmek istemiyorum, sadece mevcut iki tip bildirge olan F12 ve F34'ün bir birleşimini yaparak beyan etmek istiyorum. Bu şekilde, bu bildirimlerin herhangi birine başka bir hata türü eklediğimde F1234 bildirimini güncellemem gerekmez. F1234 = F1.type: +: F2.type: +: F34 türünü bildirebilirim ancak F1234 tipi F1234 tipi F1234 = F12: F34 türünde, extendBy işlemleri tarafından bırakılan CNil kuyruğu nedeniyle bildirimde bulunamıyorum.
Merhaba Travis, cevabınız için teşekkürler. Extend'i bulmuştum ama nasıl işe yaradığını anlayamadım. – sparkle