Can we find the first position of elements of a list satisfying a condition, with good performance, if the conditions is a tail condition of the list.
What is tail condition ? (the term is informal, personal.) I will explain with an examples.
Ex1) Let L={12,14,16,18,17,15,13}
and Cond=OddQ
, then Cond
is a tail condition of L
.
Because, the first odd number seen in the list is the 5-th element 17
, any element after 17
is also odd.
For Ex1), Earliest[L,Cond]
becomes 5
.
Ex2) Let L={12,14,17,18,16,15,13}
and Cond=OddQ
, then Cond
is not a tail condition of L
.
Because, the first odd number seen in the list is the 3-th element 17
, but there is an element that comes after 17
, which is not odd. Like 18
or 16
.
For Ex2), Earliest[L,Cond]
becomes 6
. (At present stage, you can't know why it becomes 6
.)
Note that the first odd element is 3-th, not 6-th. But complaining about this is doesn't make sense, because Earliest
is designed to work properly only if Cond
is a tail condition of L
.
Ex3) Let L={12,14,17,18,16,15,13}
and Cond=#>10&
, then Cond
is a tail condition of L
. Because every element is bigger then 10
.
For Ex3), Earliest[L,Cond]
becomes 1
.
Ex4) Let L={12,14,17,18,16,15,13}
and Cond=#>20&
, then Cond
is a tail condition of L
. Because there is no element bigger then 20
.
For Ex4), Earliest[L,Cond]
becomes Missing["NotFound"]
.
FirstPosition
? $\endgroup$r
is the result, a way to do some level of verification after the fact about having a tail condition to begin with would be to run Earliest on part;;r-1
and on partr;;
. The result should be{Missing[Not Found],1}
. $\endgroup$