在Scala中使用地图上使用地图时输入不匹配
考虑此代码:
/** Takes a list and turns it into an infinite looping stream. */
def loop(l: List[Char]): LazyList[Char] = {
l.to(LazyList) #:::loop(l)
}
/** Encodes a sequence of characters with a looped key. */
def codec(message: Seq[Char], key: Seq[Char], cipher: (Char, Char) => Char): Seq[Char] = {
val loopedKey = loop(key.toList)
val mergedMessage = message.toList zip loopedKey
val xorResult = mergedMessage.map(cipher)
xorResult.toSeq
}
循环函数正确,但是汇编后的函数 cocdec
会产生以下错误:
[error] type mismatch;
[error] found : (Char, Char) => Char
[error] required: ((Char, Char)) => ?
[error] val xorResult = mergedMessage.map(cipher)
我不明白为什么必需
part ext eap taid:> ((char,char))=> ?
。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(char,char)=> char
是一个函数,接受2chars
和返回char
而zip
将导致元组(char,char)
。一个选项是更改cipher
键入接受元组 -(((char,char))=> char
:没有更改签名 - 直接访问元组元素:
或者只使用
tupled
:(Char, Char) => Char
is a function accepting 2Chars
and returningChar
whilezip
will result in a collection of tuples(Char, Char)
. One option is to changecipher
type to accept a tuple -((Char, Char)) => Char
:Without changing the signature - access tuple elements directly:
Or just use
tupled
: