Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
これで私を助けてもらえますか:
私は2つの機能を持っています:
f1: Int => Boolean f2: Int => Boolean
今、これらの関数を次のような論理 OR で結合/マージしたいと考えています。
f3: Int => f1 || f2
したがって、関数 f3 は、関数 f1 と f2 のいずれかが true を返す場合にのみ true を返します。
そのような関数をどのように書くのですか?
どうもありがとう
def f3(n:Int) = f1(n) || f2(n)
def fun_or[T](f1: T => Boolean, f2: T => Boolean)(x: T) = f1(x) || f2(x)
それから:
val f3 = fun_or(f1, f2)
述語の作成例: http://danielwestheide.com/blog/2013/01/23/the-neophytes-guide-to-scala-part-10-staying-dry-with-higher-order-functions.html