• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala FieldType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中shapeless.labelled.FieldType的典型用法代码示例。如果您正苦于以下问题:Scala FieldType类的具体用法?Scala FieldType怎么用?Scala FieldType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了FieldType类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: transform

//设置package包名称以及导入依赖的类
package io.scalaland.chimney.internal

import shapeless.labelled.FieldType
import shapeless.{:+:, CNil, Coproduct, HList, Inl, Inr}
import samurai._

trait DerivedCoproductTransformer[From, FromLG <: Coproduct, ToLG <: Coproduct, Modifiers <: HList] {

  def transform(src: FromLG, modifiers: Modifiers): ToLG
}

object DerivedCoproductTransformer extends CoproductInstances {

  final def apply[From, FromLG <: Coproduct, ToLG <: Coproduct, Modifiers <: HList](
    implicit dct: DerivedCoproductTransformer[From, FromLG, ToLG, Modifiers]
  ): DerivedCoproductTransformer[From, FromLG, ToLG, Modifiers] = dct
}

trait CoproductInstances {

  // $COVERAGE-OFF$
  @sam implicit final def cnilCase[From, ToLG <: Coproduct, Modifiers <: HList]
    : DerivedCoproductTransformer[From, CNil, ToLG, Modifiers] =
    (_: CNil, _: Modifiers) => null.asInstanceOf[ToLG]
  // $COVERAGE-ON$

  @sam implicit final def coproductCase[From,
                                        TailFromLG <: Coproduct,
                                        Label <: Symbol,
                                        HeadToT,
                                        ToLG <: Coproduct,
                                        Modifiers <: HList](
    implicit cip: CoproductInstanceProvider[Label, HeadToT, ToLG, Modifiers],
    tailTransformer: DerivedCoproductTransformer[From, TailFromLG, ToLG, Modifiers]
  ): DerivedCoproductTransformer[From, FieldType[Label, HeadToT] :+: TailFromLG, ToLG, Modifiers] =
    (src: FieldType[Label, HeadToT] :+: TailFromLG, modifiers: Modifiers) =>
      src match {
        case Inl(head) => cip.provide(head, modifiers)
        case Inr(tail) => tailTransformer.transform(tail, modifiers)
    }
} 
开发者ID:scalalandio,项目名称:chimney,代码行数:42,代码来源:DerivedCoproductTransformer.scala


示例2: transform

//设置package包名称以及导入依赖的类
package io.scalaland.chimney.internal

import shapeless.labelled.{FieldType, field}
import shapeless.{::, HList, HNil}
import samurai._

trait DerivedProductTransformer[From, FromLG <: HList, ToLG <: HList, Modifiers <: HList] {

  def transform(src: FromLG, modifiers: Modifiers): ToLG
}

object DerivedProductTransformer extends ProductInstances {

  final def apply[From, FromLG <: HList, ToLG <: HList, Modifiers <: HList](
    implicit dpt: DerivedProductTransformer[From, FromLG, ToLG, Modifiers]
  ): DerivedProductTransformer[From, FromLG, ToLG, Modifiers] = dpt
}

trait ProductInstances {

  @sam implicit final def hnilCase[From, FromLG <: HList, Modifiers <: HList]
    : DerivedProductTransformer[From, FromLG, HNil, Modifiers] =
    (_: FromLG, _: Modifiers) => HNil

  @sam implicit final def hconsCase[From,
                                    FromLG <: HList,
                                    Label <: Symbol,
                                    HeadToT,
                                    TailToLG <: HList,
                                    Modifiers <: HList](
    implicit vp: ValueProvider[From, FromLG, HeadToT, Label, Modifiers],
    tailTransformer: DerivedProductTransformer[From, FromLG, TailToLG, Modifiers]
  ): DerivedProductTransformer[From, FromLG, FieldType[Label, HeadToT] :: TailToLG, Modifiers] =
    (src: FromLG, modifiers: Modifiers) =>
      field[Label](vp.provide(src, modifiers)) :: tailTransformer.transform(src, modifiers)
} 
开发者ID:scalalandio,项目名称:chimney,代码行数:37,代码来源:DerivedProductTransformer.scala


示例3: apply

//设置package包名称以及导入依赖的类
package magicString

import shapeless._, ops.record._, shapeless.record._, shapeless.ops.hlist._
import shapeless.labelled.{ KeyTag, FieldType }
import scala.reflect.ClassTag


trait ToStringRec[L <: HList] { def apply(l: L): List[NestedResult] }

trait LowPriorityToStringRec {
  implicit def toStringRecLow[K <: Symbol, V: ToString, L <: HList](implicit
    kWit: Witness.Aux[K],
    tailToStringRec: ToStringRec[L]): ToStringRec[FieldType[K, V] :: L] = new ToStringRec[FieldType[K, V] :: L] {
    def apply(l: FieldType[K, V] :: L): List[NestedResult] = {
      Fix[Result](Result(Some(kWit.value), ToString[V].asString(l.head.asInstanceOf[V]), Nil)) +: tailToStringRec(l.tail)
    }
  }
}

object ToStringRec extends LowPriorityToStringRec {
  implicit val hnilToStringRec: ToStringRec[HNil] = new ToStringRec[HNil] {
    def apply(l: HNil): List[NestedResult] = Nil
  }

  implicit def hconsToStringRec[K <: Symbol, V, R <: HList, T <: HList](implicit
    wit: Witness.Aux[K],
    gen: LabelledGeneric.Aux[V, R],
    tmrH: ToStringRec[R],
    tmrT: ToStringRec[T],
    ct: ClassTag[V]): ToStringRec[FieldType[K, V] :: T] = new ToStringRec[FieldType[K, V] :: T] {
    def apply(l: FieldType[K, V] :: T): List[NestedResult] =
      Fix[Result](Result(Some(wit.value), ct.runtimeClass.getName, tmrH(gen.to(l.head)))) +: tmrT(l.tail)
  }

  def toStringRec[A, L <: HList](a: A)(implicit
    gen: LabelledGeneric.Aux[A, L],
    tmr: ToStringRec[L],
    ct: ClassTag[A]): NestedResult = Fix[Result](Result(None, ct.runtimeClass.getName, tmr(gen.to(a))))
}

object Main {
  def main(args: Array[String]): Unit = {
    case class Bar(first: String, second: Int)
    case class Foo(s: String, i: Int, doubles: List[Double], bars: List[Bar])
    val foo = Foo("Hello", 1, List(3.0, 2.7), List(Bar("firstThing", 100), Bar("second", 200)))
    val bar = Bar("hello", 1)
    println(foo.magicString)
    ()
  }
} 
开发者ID:coltfred,项目名称:magicString,代码行数:51,代码来源:ToStringRec.scala


示例4: fromString

//设置package包名称以及导入依赖的类
package com.ovoenergy.comms.util

import shapeless.labelled.{FieldType, field}
import shapeless._

trait EnumFromString[A] {
  def fromString(string: String): Option[A]
}

object EnumFromString {

  implicit val fromStringCNil: EnumFromString[CNil] = new EnumFromString[CNil] {
    override def fromString(string: String) = None
  }

  implicit def fromStringCCons[K <: Symbol, V, R <: Coproduct](
      implicit wit: Witness.Aux[K],
      gen: LabelledGeneric.Aux[V, HNil],
      right: EnumFromString[R]): EnumFromString[FieldType[K, V] :+: R] =
    new EnumFromString[FieldType[K, V] :+: R] {
      override def fromString(string: String) = {
        if (wit.value.name == string)
          Some(Inl(field[K](gen.from(HNil))))
        else
          right.fromString(string).map(Inr(_))
      }
    }

  implicit def enumFromString[A, Repr <: Coproduct](implicit gen: LabelledGeneric.Aux[A, Repr],
                                                    reprFromString: EnumFromString[Repr]): EnumFromString[A] =
    new EnumFromString[A] {
      override def fromString(string: String) =
        reprFromString.fromString(string).map(gen.from)
    }

  def apply[A](implicit ev: EnumFromString[A]): EnumFromString[A] = ev

} 
开发者ID:ovotech,项目名称:comms-kafka-messages,代码行数:39,代码来源:EnumFromString.scala


示例5: hListObjectWrites

//设置package包名称以及导入依赖的类
package microtools.shapeless

import play.api.data.validation.ValidationError
import play.api.libs.json._
import shapeless.labelled.{FieldType, field}
import shapeless.{:+:, ::, CNil, Coproduct, Generic, HList, HNil, Inl, Inr, Lazy, Witness}

trait ShapelessObjectJson {
  implicit val hNilWrites: OWrites[HNil] = OWrites[HNil](_ => Json.obj())

  implicit val hNilReads: Reads[HNil] = Reads(_ => JsSuccess(HNil))

  implicit def hListObjectWrites[K <: Symbol, H, T <: HList](
      implicit witness: Witness.Aux[K],
      hWrites: Lazy[Writes[H]],
      tWrites: OWrites[T]
  ): OWrites[FieldType[K, H] :: T] = OWrites[FieldType[K, H] :: T] {
    case head :: tail =>
      val name = witness.value.name
      val h    = hWrites.value.writes(head)
      val t    = tWrites.writes(tail)

      Json.obj(name -> h) ++ t
  }

  implicit def hListObjectReads[K <: Symbol, H, T <: HList](
      implicit witness: Witness.Aux[K],
      hReads: Lazy[Reads[H]],
      tReads: Reads[T]
  ): Reads[FieldType[K, H] :: T] = Reads[FieldType[K, H] :: T] { json =>
    ((json \ witness.value.name).validate(hReads.value), json.validate(tReads)) match {
      case (JsSuccess(h, _), JsSuccess(t, _))   => JsSuccess(field[K](h) :: t)
      case (JsError(errors1), JsError(errors2)) => JsError(errors1 ++ errors2)
      case (JsError(errors), _)                 => JsError(errors)
      case (_, JsError(errors))                 => JsError(errors)
    }
  }
}

object ShapelessObjectJson extends ShapelessObjectJson 
开发者ID:21re,项目名称:play-micro-tools,代码行数:41,代码来源:ShapelessObjectJson.scala


示例6: GenericReader

//设置package包名称以及导入依赖的类
package com.github.lavrov.xml.reader

import cats.Applicative
import com.github.lavrov.xml.reader.XmlPath.__
import shapeless.labelled.FieldType
import shapeless.{::, HList, HNil, LabelledGeneric, Witness}

object GenericReader {

  implicit def fieldTypeReader[K <: Symbol, V](
      implicit
      witness: Witness.Aux[K],
      vReader: Reader[V]
  ): Reader[FieldType[K, V]] = {
    (__ \ witness.value.name).read[V].asInstanceOf[Reader[FieldType[K, V]]]
  }

  implicit def hNilReader: Reader[HNil] = Reader.pure(HNil)

  implicit def hListReader[H, T <: HList](
      implicit
      hReader: Reader[H],
      tReader: Reader[T]
  ): Reader[H :: T] = {
    Applicative[Reader].product(hReader, tReader).map {
      case (head, tail) => head :: tail
    }
  }

  implicit def genericReader[A, Repr](
      implicit
      gen: LabelledGeneric.Aux[A, Repr],
      reader: Reader[Repr]
  ): Reader[A] = reader.map(gen.from)

} 
开发者ID:lavrov,项目名称:xml-reader,代码行数:37,代码来源:GenericReader.scala


示例7: SelectAll

//设置package包名称以及导入依赖的类
package spinoco.fs2.cassandra.internal

import shapeless.labelled.FieldType
import shapeless.ops.record.Selector
import shapeless.{::, DepFn1, HList, HNil}


@annotation.implicitNotFound(msg = "No fields ${K} in record ${L}")
trait SelectAll[L <: HList, K <: HList] extends DepFn1[L] with Serializable { type Out <: HList }

object SelectAll {
  def apply[L <: HList, K <: HList](implicit sa: SelectAll[L, K]): Aux[L, K, sa.Out] = sa

  type Aux[L <: HList, K <: HList, Out0 <: HList] = SelectAll[L, K] { type Out = Out0 }

  implicit def hnilSelectAll[L <: HList]: Aux[L, HNil, HNil] =
    new SelectAll[L, HNil] {
      type Out = HNil
      def apply(l: L): Out = HNil
    }

  implicit def hconsSelectAll[L <: HList, K,V, KT <: HList]
  (implicit
   sh: Selector.Aux[L, K,V],
   st: SelectAll[L, KT]
  ): Aux[L, FieldType[K,V] :: KT, FieldType[K,V] :: st.Out] =
    new SelectAll[L, FieldType[K,V] :: KT] {
      type Out = FieldType[K,V] :: st.Out
      def apply(l: L): Out = sh(l).asInstanceOf[FieldType[K,V]] :: st(l)
    }
} 
开发者ID:Spinoco,项目名称:fs2-cassandra,代码行数:32,代码来源:SelectAll.scala


示例8: hlistSchema

//设置package包名称以及导入依赖的类
package com.timeout.docless.schema.derive

import com.timeout.docless.schema._
import JsonSchema._
import shapeless._
import io.circe._
import io.circe.syntax._
import shapeless.labelled.FieldType
import reflect.runtime.{universe => ru}

trait HListInstances {
  implicit val hNilSchema: JsonSchema[HNil] = inlineInstance(
    JsonObject.fromMap(Map.empty)
  )

  implicit def hlistSchema[K <: Symbol, H, T <: HList](
      implicit witness: Witness.Aux[K],
      lazyHSchema: Lazy[JsonSchema[H]],
      lazyTSchema: Lazy[JsonSchema[T]]
  ): JsonSchema[FieldType[K, H] :: T] = instanceAndRelated {
    val fieldName = witness.value.name
    val hSchema   = lazyHSchema.value
    val tSchema   = lazyTSchema.value
    val (hValue, related) =
      if (hSchema.inline)
        hSchema.asJson -> tSchema.relatedDefinitions
      else
        hSchema.asJsonRef -> (tSchema.relatedDefinitions + hSchema
          .NamedDefinition(fieldName))

    val hField  = fieldName -> hValue
    val tFields = tSchema.jsonObject.toList

    JsonObject.fromIterable(hField :: tFields) -> related
  }

  implicit def genericSchema[A, R <: HList](
      implicit gen: LabelledGeneric.Aux[A, R],
      rSchema: JsonSchema[R],
      fields: Required.Fields[R],
      tag: ru.WeakTypeTag[A]
  ): JsonSchema[A] =
    instanceAndRelated[A] {
      JsonObject.fromMap(
        Map(
          "type"       -> Json.fromString("object"),
          "required"   -> fields.asJson,
          "properties" -> rSchema.jsonObject.asJson
        )
      ) -> rSchema.relatedDefinitions
    }

} 
开发者ID:timeoutdigital,项目名称:docless,代码行数:54,代码来源:HListInstances.scala


示例9: apply

//设置package包名称以及导入依赖的类
package patchless

import shapeless.labelled.{FieldType, field}
import shapeless._

sealed trait Patchable[T] {
  type Updates <: HList
  def apply(t: T, updates: Updates): T
}

object Patchable {
  type Aux[T, U <: HList] = Patchable[T] { type Updates = U }

  def apply[T](implicit patchable: Patchable[T]): Aux[T, patchable.Updates] = patchable

  implicit val hnil: Aux[HNil, HNil] = new Patchable[HNil] {
    final type Updates = HNil
    def apply(t: HNil, updates: HNil): HNil = HNil
  }

  implicit def hcons[K <: Symbol, H, T <: HList, TU <: HList](implicit
    patchTail: Aux[T, TU]
  ): Aux[FieldType[K, H] :: T, FieldType[K, Option[H]] :: TU] = new Patchable[FieldType[K, H] :: T] {
    final type Updates = FieldType[K, Option[H]] :: TU
    def apply(t: FieldType[K, H] :: T, updates: FieldType[K, Option[H]] :: TU) =
      field[K](updates.head.getOrElse(t.head)) :: patchTail(t.tail, updates.tail)
  }

  implicit def generic[T, L <: HList, U <: HList](implicit
    gen: LabelledGeneric.Aux[T, L],
    patchL: Aux[L, U]
  ): Aux[T, U] = new Patchable[T] {
    final type Updates = U
    def apply(t: T, updates: U) = gen.from(patchL(gen.to(t), updates))
  }
} 
开发者ID:jeremyrsmith,项目名称:patchless,代码行数:37,代码来源:Patchable.scala


示例10: headNotCaseClassDeepHLister

//设置package包名称以及导入依赖的类
package fluent.internal

import shapeless.labelled.FieldType
import shapeless.ops.hlist.Prepend
import shapeless.{ ::, DepFn1, HList, HNil, LabelledGeneric, Lazy }


trait DeepHLister[R <: HList] extends DepFn1[R] { type Out <: HList }

trait LowPriorityDeepHLister {
  type Aux[R <: HList, Out0 <: HList] = DeepHLister[R] { type Out = Out0 }

  implicit def headNotCaseClassDeepHLister[H, T <: HList](
    implicit dht: Lazy[DeepHLister[T]]
  ): Aux[H :: T, H :: dht.value.Out] = new DeepHLister[H :: T] {
    type Out = H :: dht.value.Out
    def apply(r: H :: T): Out = r.head :: dht.value(r.tail)
  }
}

object DeepHLister extends LowPriorityDeepHLister {
  def apply[R <: HList](implicit dh: DeepHLister[R]): Aux[R, dh.Out] = dh

  implicit object hnilDeepHLister extends DeepHLister[HNil] {
    type Out = HNil
    def apply(r: HNil): Out = HNil
  }

  implicit def headCaseClassDeepHLister[K, V, R <: HList, T <: HList, OutR <: HList, OutT <: HList, Out0 <: HList](
    implicit
    gen: LabelledGeneric.Aux[V, R],
    dhh: Lazy[DeepHLister.Aux[R, OutR]],
    dht: Lazy[DeepHLister.Aux[T, OutT]],
    prepend: Prepend.Aux[OutR, OutT, Out0]
  ): Aux[FieldType[K, V] :: T, Out0] = new DeepHLister[FieldType[K, V] :: T] {
      type Out = Out0
      def apply(r: FieldType[K, V] :: T): Out = prepend(dhh.value(gen.to(r.head.asInstanceOf[V])), dht.value(r.tail))
  }
} 
开发者ID:btlines,项目名称:fluent,代码行数:40,代码来源:DeepHLister.scala



注:本文中的shapeless.labelled.FieldType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala PasswordHasher类代码示例发布时间:2022-05-23
下一篇:
Scala SortedSet类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap