Functional way to find a pair of integers, which sum to X, in a sorted array
问题 This is a follow-up to my previous question. Suppose I want to find a pair of integers, which sum to a given number x , in a given sorted array. The well-known "one pass" solution looks like that: def pair(a: Array[Int], target: Int): Option[(Int, Int)] = { var l = 0 var r = a.length - 1 var result: Option[(Int, Int)] = None while (l < r && result.isEmpty) { (a(l), a(r)) match { case (x, y) if x + y == target => result = Some(x, y) case (x, y) if x + y < target => l = l + 1 case (x, y) if x +