-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename occursin to something more reasonable #30368
Comments
History:
In short: English doesn't have a good short word for subsequence matching. We've tried many different ways of naming this operation. |
Thought: Perl and Ruby use |
That looks like it should be an updating |
I kind of just want to write Simplistic example: struct SubSeqs # All sub sequences of a string
str::String
end
Base.in(pat, ss::SubSeqs) = occursin(pat, ss.str) Thence julia> "foo" in SubSeqs("asdf foo x")
true Unfortunately it's not a completely clean decomposition of the problem when you come to matching regex or other pattern types, as these patterns have their own notion of whether the pattern must match the whole string, or merely a subsequence. I'm not sure whether that's a fatal problem yet. |
at least |
We put back |
ismatch(r::Regex) = (s) -> match(r, string(s)) !== nothing # could go in Base
using Test
@test filter(ismatch(r"[c-e]"), 'a':'z') == ['c','d','e'] Works not so well with EDIT:
BTW |
Everytime I encounter this function I visually parse it as
occur_sin
, and personally find it ugly.From slack there seems to be a lot of people that share this sentiment. It might be good to rename this function.
I tried searching for other programming languages that use the name
occursin
. I found some usages where it was spelled asoccursIn
in Java, which would more closely translate tooccurs_in
in Julia (however I'm not a fan of the underscore and this is something that Base Julia tries to avoid in general).Stefan threw out the following in the thread:
and later on threw out:
ismatch
The text was updated successfully, but these errors were encountered: