I have tailrec version of `detectSequence`. I think it has the same logic, expect that it bails out faster if it find characters not to be ignored. The only additional cost is the `codeString.toList`.
I prefer it, it expose more the different cases, but I don't know if it is a lot better.


```scala
  private def detectSequence(codeString: String, sequenceFuncs: List[Char => Boolean], marked: Int, isIgnored: Char => Boolean): Option[Int] = {

    @tailrec
    def loop(code: List[Char], sequenceFuncs: List[Char => Boolean], toMarked: Int, index: Int, indexMarked: Int): Option[Int] = {
      code match {
        case Nil =>
          if (sequenceFuncs.isEmpty) {
            // codeString and sequence terminated at the same time, all good
            Some(indexMarked)
          } else {
            // codeString terminated, but not the sequence
            None
          }
        case c :: codeTail =>
          sequenceFuncs match {
            case Nil =>
              // found all elements of the sequence, check if all the remainder chars are to be ignored
              if (code.forall(isIgnored)) {
                Some(indexMarked)
              } else {
                None
              }
            case f :: fTail =>
              if (f(c)) {
                // right character for the sequence
                if (toMarked == 0) { // keep track of the index if needed
                  loop(codeTail, fTail, -1, index + 1, index)
                } else {
                  loop(codeTail, fTail, toMarked - 1, index + 1, indexMarked)
                }
              } else if (isIgnored(c)){ // continue if the char can be ignored
                loop(codeTail, sequenceFuncs, toMarked, index + 1, indexMarked)
              } else { // char not in sequence and not to be ignored
                None
              }
          }
      }
    }

    loop(codeString.toList, sequenceFuncs, marked, 0, -1)
  }
```