Reputation: 3863
I'm trying to solve this problem. I want to implement this function in Scala
def toSeq[U,T](f: U=>Seq[T]): Stream[U=>T] = ???
I guess the solution should make use of Stream, but I don't know how to solve this.
EDIT
I will try to describe the use case that lead me to this problem. I am creating a DSL to express extractions of data from different datasources. The DSL allows to define extractions like this (U is the source type and T is the extraction type)
type Mapping[-U, T] = U => T
trait Source[T , U]
case class SingleValueSource[T U](mappings: Seq[Mapping[U, T]]) extends Source[T, U]
case class OptionalValueSource[T , U](mappings: Seq[Mapping[U, Option[T]]]) extends Source[T, U]
case class SeqValueSource[T , U](mapping: Mapping[U, Seq[T]]) extends Source[T, U]
I want to be able to combine all this mappings to build new Source, for example
def addMapping(source: Source[U,T], mapping: Mapping[U, T]): Source[U,T]
def addMapping(source: Source[U,T], mapping: Mapping[U, Option[T]]): Source[U,T]
def addMapping(source: Source[U,T], mapping: Mapping[U, Seq[T]]): Source[U,T]
The function I am asking came up when I was trying to implement
def addMapping(source: SeqValueSource[U,T], mapping: Mapping[U, Option[T]]): Source[U,T]
But maybe there's a better way
Upvotes: 0
Views: 147