I have a function map
which takes a Parser
and a function defined as follows:
def map[T1, T2](parser: Parser[T1], func: T1 => T2): Parser[T2]
I've created a Parser
object of type [(Char, Char)]
and a function (Char, Char) => String
.
val parser[(Char,Char)] = //...
val asString: (Char, Char) => String = (a: Char, b: Char) => a.toString + b.toString
And then I pass these two to the map
function.
val mParser: Parser[String] = map(parser, asString)
I expect everything to work fine but I get a type mismatch error for asString
argument saying
Error:(26, 41) type mismatch;
found : (Char, Char) => String
required: ((Char, Char)) => String
map[(Char, Char), String](parser, asString)
I have tried to explicitly specify the types for map
as map[(Char, Char), String](parser, asString)
but that didn't help either.
The type T1
here is the char tuple (Char, Char)
and T2
is a String
. So, the function (Char, Char) => String
is what's supposed to be the input but scala is expecting a different type.
What am I missing here? Why is it expecting ((Char, Char)) => String
instead of (Char,Char) => String
?
I'm using Scala 2.12. Don't know if that is relevant in any way.
Your help is appreciated.
map(parser -> asString)
? Here you can get more information about Map. – tea-addictmap
function I've defined. – Durga Swaroop