Julia: Bring back contains(haystack, needle)

Created on 6 Mar 2020  路  2Comments  路  Source: JuliaLang/julia

Right now we have:

  • startswith(haystack, needle)
  • endswith(haystack, needle)
  • and occursin(needle, haystack)

While occursin(needle, haystack) is right from the perspective of reading
f(a, b) as a f b
i.e. needle occursin haystack

It is not consistent with startwith or endswith.

Back in julia 0.6 (IIRC) we had contains(haystack, needle)
which still reads right: haystack contains needle.

I would like to suggest we bring it back so that we can have that consistency.


This is part of a series of issues relating to https://github.com/invenia/Wrangling.jl/pull/3
Will link others below for cross referencing.
https://github.com/JuliaLang/julia/issues/35032
https://github.com/JuliaLang/julia/issues/35033

Most helpful comment

Ok I will make the PR to add contains after https://github.com/JuliaLang/julia/pull/35052 is merged
because I think it should also match startwith and endswith having curried versions.

Since it will follow that pattern

All 2 comments

Yes, I miss this a lot. IIRC, the reason we settled on occursin was that we were worried that contains(haystack, needle) confusing element containment with subsequence containment, but I think we already mix that up a bit so maybe it doesn't matter.

Ok I will make the PR to add contains after https://github.com/JuliaLang/julia/pull/35052 is merged
because I think it should also match startwith and endswith having curried versions.

Since it will follow that pattern

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wilburtownsend picture wilburtownsend  路  3Comments

helgee picture helgee  路  3Comments

TotalVerb picture TotalVerb  路  3Comments

musm picture musm  路  3Comments

i-apellaniz picture i-apellaniz  路  3Comments