def filter_to_proc(filter)
      if filter.respond_to?(:to_a)
        filter_procs_from_array(filter)
      elsif filter.respond_to?(:to_str)
        filter_proc_from_string(filter)
      elsif regexp_filter = Regexp.try_convert(filter)
        ->(token) {
          token =~ regexp_filter
        }
      elsif filter.respond_to?(:to_proc)
        filter.to_proc
      else
        raise ArgumentError,
          "`filter` must be a `String`, `Regexp`, `lambda`, `Symbol`, or an `Array` of any combination of those types"
      end
    end
def filter_to_proc(filter)
      if filter.respond_to?(:to_a)
        filter_procs_from_array(filter)
      elsif filter.respond_to?(:to_str)
        filter_proc_from_string(filter)
      elsif regexp_filter = Regexp.try_convert(filter)
        ->(token) {
          token =~ regexp_filter
        }
      elsif filter.respond_to?(:to_proc)
        filter.to_proc
      else
        raise ArgumentError,
          "`filter` must be a `String`, `Regexp`, `lambda`, `Symbol`, or an `Array` of any combination of those types"
      end
    end
The following methods convert any arguments into a callable object. The return value of this
 lambda is then used to determine whether a token should be excluded from the final list.

 `filter` can be a string, a regular expression, a lambda, a symbol, or an array
 of any combination of those types.

 If `filter` is a string, it converts the string into an array, and returns a lambda
 that returns true if the token is included in the resulting array.

 @see {Tokeniser#filter_proc_from_string}.

 If `filter` is a an array, it creates a new array where each element of the origingal is
 converted to a lambda, and returns a lambda that calls each lambda in the resulting array.
 If any lambda returns true the token is excluded from the final list.

 @see {Tokeniser#filter_procs_from_array}.

 If `filter` is a proc, then the proc is simply called. If `filter` is a regexp, a `lambda`
 is returned that checks the token for a match.

 If a symbol is passed, it is converted to a proc. The symbol must name a predicate method.

 This method depends on `nil` responding `to_a` with an empty array, which
 avoids having to check if `exclude` was passed.
 @api private