在单行中缓存一个中间变量

问题描述:

我可以在这个简单的函数定义中以某种方式缓存 i.toString 吗?

Can I somehow cache the i.toString in this simple definition of function?

def palindrome(i: Int) = i.toString == i.toString.reverse

我想让这个函数保持简单,没有经典的多行、大括号括起来的函数..

I want to keep this function simple, w/o a classic multi-line, brace-enclosed function..

您可以:

def palindrome(i: Int) = ((s:String) => s == s.reverse)(i.toString)