Alternatively, if the length is always known at code-writing-time (eg, 2):

```
julia> function foo2(a,b)
t = 0.99
@inbounds for i = 2:length(b)
if any(x -> x > t, (b[i-1], b[i]))
end
end
end
foo2 (generic function with 1 method)
julia> @btime foo2($a, $b)
10.270 ns (0 allocations: 0 bytes)
```

Unfortunately, to make it work at compile time, you’d need generated functions because of inference failure on `ntuple`

:

```
julia> function foo4(a,b)
t = 0.99
@inbounds for i = 2:length(b)
if any(x -> x > t, ntuple(j -> b[i+j-2], Val(2)))
end
end
end
foo4 (generic function with 1 method)
julia> @btime foo4($a, $b)
3.181 μs (56 allocations: 1.25 KiB)
```

But if we want to take that approach, the function is simple enough for the compiler to cheat:

```
julia> @generated function foo5(a,b,::Val{N} = Val(2)) where N
quote
t = 0.99
@inbounds for i = 2:length(b)
if any((Base.Cartesian.@ntuple $N j -> b[i+j-2] > t))
end
end
end
end
foo4 (generic function with 2 methods)
julia> @btime foo5($a, $b)
1.202 ns (0 allocations: 0 bytes)
julia> @btime foo4($a, $b)
1.482 ns (0 allocations: 0 bytes)
julia> a = rand(10^6);
julia> b = rand( 10^6 - 1);
julia> @btime foo5($a, $b)
1.482 ns (0 allocations: 0 bytes)
```

because now the compiler realizes the code isn’t actually doing anything.