hlist

Can Map be performed on a Scala HList

谁说我不能喝 提交于 2019-12-04 07:44:24
问题 I have done a few implementations of HList now. One based on Daniel Spiewak's High Wizardry in the Land of Scala talk and another based on a post in Apocalisp blog. The goal was to have a heterogenous list of which is not heterogenous in the primary type but rather the higher kind. For example: val requests = Request[String] :: Request[Int] :: HNil I would be able to do a map across the list to perform the request and result in a heterogenous list of the higher kind. So: requests.map(execute)

Map on HList in method with Poly1 based on type parameter of class

落爺英雄遲暮 提交于 2019-12-03 16:03:19
I have class, parameterized with HList and some other type. How can I use map on HList in one of its methods? Compilation of this code throws java.lang.AssertionError : class Test[L <: HList, P](l: L, p: P) { type Cont[T] = (P, T) object generator extends (Id ~> Cont) { def apply[T](t: T) = p -> t } def test(implicit m: Mapper[generator.type, L]) = { l map generator } } new Test(1 :: HNil, 'a).test // java.lang.AssertionError My goal is this kind of result: type Cont[T] = (Symbol, T) val p = 'a object generator extends (Id ~> Cont) { def apply[T](t: T) = p -> t } scala> (1 :: 'b' :: HNil) map

How can I use the new Slick 2.0 HList to overcome 22 column limit?

谁都会走 提交于 2019-12-03 11:38:16
问题 I'm currently writing Slick code to target an old schema with two tables > 22 columns. How do I use the new HList code? I've got 2.0-M3 working fine in other respects under Scala 2.10.3. Here's the syntax I'm currently using with case classes / tuples. What would I do to use the new HLists mentioned in the docs? case class Joiner( id: Int, name: Option[String], contact: Option[String] ) class Joiners(tag: Tag) extends Table[Joiner](tag, "joiner") { def id = column[Int]("id", O.PrimaryKey, O

Find type class instances for Shapeless HList

喜夏-厌秋 提交于 2019-12-03 07:03:30
Say that I have a trait Show[T] such as the one in Scalaz: https://github.com/scalaz/scalaz/blob/scalaz-seven/core/src/main/scala/scalaz/Show.scala#L9 I also have a Shapeless HList that may look like "1" :: 2 :: 3L :: HNil . Is there a way to find the Show instance for each element and apply shows such that I end up with "1" :: "2" :: "3L" :: HNil ? If any element were of a type that did not have an implicit Show instance in scope I would want a compile error. I think that if I build up an HList of the Show instances I should be able to use zipApply to get the HList I want, but I don't know if

Can Map be performed on a Scala HList

寵の児 提交于 2019-12-02 15:50:26
I have done a few implementations of HList now. One based on Daniel Spiewak's High Wizardry in the Land of Scala talk and another based on a post in Apocalisp blog. The goal was to have a heterogenous list of which is not heterogenous in the primary type but rather the higher kind. For example: val requests = Request[String] :: Request[Int] :: HNil I would be able to do a map across the list to perform the request and result in a heterogenous list of the higher kind. So: requests.map(execute) should equal String :: Int :: HNil Sadly all my attempts have resulted in an HList of Any. Here is the

Shapeless: own HList constraint using Coproduct

假如想象 提交于 2019-12-01 23:08:50
(NOTE: Split from Shapeless: Trying to restrict HList elements by their type ) Question 2 - Own Constraint using Coproduct What I really wanted to do is to write a new constraint using Coproduct. trait CPConstraint[L <: HList, CP <: Coproduct] extends Serializable object CPConstraint { import shapeless.ops.coproduct.Selector._ def apply[L <: HList, CP <: Coproduct](implicit cpc: CPConstraint[L, CP]): CPConstraint[L, CP] = cpc type <*<[CP <: Coproduct] = { // TODO: just invented a symbol ... what would be an appropriate one? type λ[L <: HList] = CPConstraint[L, CP] } implicit def hnilCP[HN <:

Heterogeneous arguments in a Scala function

与世无争的帅哥 提交于 2019-11-30 14:01:01
How can I pass some HList as an argument? So I can make in a such way: def HFunc[F, S, T](hlist: F :: S :: T :: HNil) { // here is some code } HFunc(HList(1, true, "String")) // it works perfect But if I have a long list, and I dunno nothing about it, how can I make some operations on it? How can I pass argument and not to loose its type? It depends on your use-case. HList is useful for type-level code, so you should pass to your method not only HList , but also all necessary information like this: def hFunc[L <: HList](hlist: L)(implicit h1: Helper1[L], h2: Helper2[L]) { // here is some code

Heterogeneous arguments in a Scala function

孤街浪徒 提交于 2019-11-29 19:22:35
问题 How can I pass some HList as an argument? So I can make in a such way: def HFunc[F, S, T](hlist: F :: S :: T :: HNil) { // here is some code } HFunc(HList(1, true, "String")) // it works perfect But if I have a long list, and I dunno nothing about it, how can I make some operations on it? How can I pass argument and not to loose its type? 回答1: It depends on your use-case. HList is useful for type-level code, so you should pass to your method not only HList , but also all necessary information

How to correctly type-annotate this HList?

可紊 提交于 2019-11-29 07:59:06
sealed abstract trait HList case class :+:[H, T <: HList](head: H, tail: T) extends HList { def :+:[T](v: T) = new :+:(v, this) } case object HNil extends HList { def :+:[T](v: T) = new :+:(v, this) } object HListExpt { def main(args: Array[String]) { val me: String :+: Int :+: Symbol :+: HNil.type = "Rahul" :+: 20 :+: 'Male :+: HNil println(me.head, me.tail.head) } } On trying to compile the above code, I get the following compiler error: error: type mismatch; found : :+:[java.lang.String,:+:[Int,:+:[Symbol,object HNil]]] required: :+:[String,:+:[Int,:+:[Symbol,HNil.type]]] val me: String :+:

How to correctly type-annotate this HList?

两盒软妹~` 提交于 2019-11-28 01:21:41
问题 sealed abstract trait HList case class :+:[H, T <: HList](head: H, tail: T) extends HList { def :+:[T](v: T) = new :+:(v, this) } case object HNil extends HList { def :+:[T](v: T) = new :+:(v, this) } object HListExpt { def main(args: Array[String]) { val me: String :+: Int :+: Symbol :+: HNil.type = "Rahul" :+: 20 :+: 'Male :+: HNil println(me.head, me.tail.head) } } On trying to compile the above code, I get the following compiler error: error: type mismatch; found : :+:[java.lang.String,:+