function getTailmostMatchingChain(items, matcher) {
  const onlyMatched = items.map((item) => (matcher(item) ? item : null))
  const lastIndex = onlyMatched.lastIndexOf(null)
  return /** @type {T[]} */ (
    lastIndex === -1 ? onlyMatched.slice() : onlyMatched.slice(lastIndex + 1)
  )
}
@template {any} T
@param {T[]} items
@param {(item: T) => item is T} matcher
@returns {T[]}