class Step
case class Publish(p: String) extends Step
case class Receive(p: String) extends Step
class Data
case class Input(p: Int) extends Data
case class Output(p: Int) extends Data
type P = Publish
type R = Receive
type I = Input
type O = Output
I would like to define an object that takes a sequence of Step and returns a sequence of Data, according to this mapping:
P -> I and
R -> O.
So, if the sequence is: P, R, P, R, R, P, R, the result should be: I, O, I, O, O, I, O.
Right now I have this objects, which may clarify what I'm trying to do:
object Flow {
def apply[T <: HList, S <: HList](t: T)
(implicit mapper : Mapper[IOFlow.type, T]): S => Unit = {
val s = t.map(IOFlow)
s => ()
}
}
object IOFlow extends Poly1 {
implicit val in = at[P]{ i => makeI(i) }
implicit val out = at[R]{ r => makeO(r) }
def makeI(p: P) = Input // so the return type is Input.type
def makeO(p: R) = Output // and Output.type
}
object Main extends App {
val initialList = HList(P("1"), R("2"), P("3"), R("4"), R("5"), P("6"), R("7"))
val flow = Flow(initialList)
}
Right now, this gives me an error, which actually occurs at val s = t.map(IOFlow):
Error: could not find implicit value for parameter mapper: shapeless.ops.hlist.Mapper[com.tasegula.scala.shapeless.IOFlow.type,this.Repr]
val flow = Flow(hlist)
^
Trying to resolve this, I stumbled upon this topic, which have a source code here.
I can't compile and run the code because I can't find that MapperAux class (line 36).
So the questions are:
1. How can I give an implicit mapper?
2. Is there a way to change the Flow#apply
method declaration to apply(t: Step*)
, so the call would be Flow(P("1"), R("2"), P("3"), R("4"), R("5"), P("6"), R("7"))
?