Subvector pattern matching

A simple way to do this would be:

using IterTools

any(((i,j,k),) -> (i == k) && (j >= k+1), partition([1, 3, 1, 4], 3, 1))
# true

any(((i,j,k),) -> (i == k) && (j >= k+1), partition([1, 0, 1, 4], 3, 1))
# false

Most of the parenthesis are necessary (sorry). The vector is clearly seen as a parameter to partition, and the other parameters are the window size (3) and stepping amount (1). The (i,j,k) takes advantage of automatic destructuring of tuples. Overall this would probably be also a most efficient way to achive the OP results (it short-circuits if it finds a match).

1 Like