Julia: Allow searching for subvectors of vectors in contains

Created on 24 Oct 2017  路  3Comments  路  Source: JuliaLang/julia

I'd have expected the following to work:

julia> contains(UInt8[1, 2, 3], UInt8[2, 3])
ERROR: MethodError: no method matching contains(::Array{UInt8,1}, ::Array{UInt8,1})
Closest candidates are:
  contains(::Function, ::Any, ::Any) at reduce.jl:664

having the same meaning as it does for strings.

search & find

Most helpful comment

BTW, contains could be integrated to the find* family of functions. We could keep it as a convenience function, with a fallback to something like findfirst(sequence(needle), haystack) > 0.

All 3 comments

BTW, contains could be integrated to the find* family of functions. We could keep it as a convenience function, with a fallback to something like findfirst(sequence(needle), haystack) > 0.

See also https://github.com/JuliaLang/julia/issues/19250 and https://github.com/JuliaLang/julia/pull/18028. I think we should get rid of ismatch which is quite restrictive as it only works with regular expressions, and merge it with contains. This appears to be the consensus.

My only slight concern is that find* works with indices, and there could be cases where a sequence doesn't have indices or where it's more expensive to determine an index than to determine whether a match exists. But find* works for all current cases, so we can go ahead with switching to find*, and possibly add an issubseq that defaults to calling find(needle, haystack) > 0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanKarpinski picture StefanKarpinski  路  3Comments

TotalVerb picture TotalVerb  路  3Comments

i-apellaniz picture i-apellaniz  路  3Comments

helgee picture helgee  路  3Comments

wilburtownsend picture wilburtownsend  路  3Comments