Erlang: First element in a list matching some condition (without evaluating the rest of the elements)
问题 As a simple example, suppose I have a list of numbers L and I want to find the first element that is greater than some specific number X . I could do this with list comprehensions like this: (mynode@127.0.0.1)24> L = [1, 2, 3, 4, 5, 6]. [1,2,3,4,5,6] (mynode@127.0.0.1)25> X = 2.5. 2.5 (mynode@127.0.0.1)26> [First | _] = [E || E <- L, E > X]. [3,4,5,6] (mynode@127.0.0.1)27> First. 3 But this seems potentially very inefficient, since the list could be very long and the first match could be