Does Elixir handle matching values relative to constants in any way? An example of this would be ::
All the examples are a pseudo syntax for the idea
- (the value after) 3 = x
- iex>
[ _ | [ 3 | [ x | _ ] ] ] = [1,2,3,4,5,6,7] // x = 4 - (the value before 6) = x
- iex>
[ _ | [ x | [ 6 | _ ] ] ] = [1,2,3,4,5,6,7] // x = 5 - (the sublist of values between 3 and 6) = x
- iex>
[ _ | [ 3 | [ x | [ 6 | _ ] ] ] ] = [1,2,3,4,5,6,7] // x = [4,5] - (the sublist of the 3 values after 4) = [a,b,c]
- iex>
[ _ | [ 3 | [ [a,b,c] | _ ] ] = [1,2,3,4,5,6,7] // x = [5,6,7]
Unfortunately most books and online documentation only covers absolute positioning from the first index, such as N elements from the head via [ head | tail ] but as the target value gets farther from the first element this becomes kinda silly with syntax like [ _ | [ _ | [ _ | [ x | _ ] ] ] ] to get the 4th element in a list.
Is there any syntax for matching relative indexes of a list? An example of incorrect but conceptually plausible syntax would be getting the last index in a list via [ _ | [ x | [] ] ] or getting the value after the index of 3 via [ _ | [ 3 | [ x | _ ] ] ]