Skip to content
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

add partially-applied versions of ∋, ∉, ∌, occursin #38475

Merged
merged 1 commit into from
Dec 7, 2020

Conversation

JeffBezanson
Copy link
Sponsor Member

in(x) is really useful, but sometimes I want this for the other argument. E.g.

julia> findall(∋(0), [-1:1, 1:10, -2:20])
2-element Vector{Int64}:
 1
 3

for finding ranges that contain 0. It's not great that this requires unicode --- is there another name for this already? If not, should we add one?

@KristofferC
Copy link
Sponsor Member

ni!

@Keno
Copy link
Member

Keno commented Nov 17, 2020

inleft?

@StefanKarpinski
Copy link
Sponsor Member

I actually like calling it ni 😬

@JeffBezanson
Copy link
Sponsor Member Author

Other languages may try to reference it, but WE ARE THE DEVS WHO SAY "NI"!

@mcabbott
Copy link
Contributor

There is findall(contains('a'), ["cat", "dog", "zebra"]) but only for strings. For which findall(in("cat"), 'a':'e') works but occursin("cat") does not.

@JeffBezanson
Copy link
Sponsor Member Author

Yeah we should also add occursin(x).

@nickrobinson251
Copy link
Contributor

we should also add occursin(x).

I think this criteria is the reason we don't have occursin(x) (and one of the motivations for adding the argument-flipped contains function was that it fit the criteria for having a partially-applied one-arg method).

@StefanKarpinski
Copy link
Sponsor Member

These definitions would both fit the criteria:�

  • occursin(haystack) would be needle -> occursin(needle, haystack)
  • contains(needle) would be haystack -> contains(haystack, needle).

@jw3126
Copy link
Contributor

jw3126 commented Nov 25, 2020

ni!

We should add more pythonic then python to the greed of julia.

@stevengj
Copy link
Member

stevengj commented Dec 1, 2020

Needs docs and/or NEWS?

@JeffBezanson JeffBezanson added the status:triage This should be discussed on a triage call label Dec 1, 2020
@JeffBezanson JeffBezanson changed the title RFC: add partially-applied versions of ∋, ∉, ∌ RFC: add ni and partially-applied versions of ∋, ∉, ∌, occursin Dec 1, 2020
@JeffBezanson
Copy link
Sponsor Member Author

Added all the things.

@nickrobinson251
Copy link
Contributor

nickrobinson251 commented Dec 1, 2020

oh... it's really gonna be called ni 😆 I don't want to bikeshed this too much, but it does seem a bit funny... since it's not a word. Maybe that's fine, because in practice will probably be used instead, and this is just for when an ascii name is required for some reason?

I didn't want to raise a naming question without an alternative suggestion, so... How about has? e.g. has([1, 2, 3], 2), any(has(0), (-1:1, 1:3))? it's still very short, basically another word for contains, probably fine to claim as name (i've never seen a has function before), and i think consistent enough with functions names with a has* prefix, like haskey, hasvalue etc.

(I don't feel strongly, so don't hold up the PR over this if everyone else is in favour of ni ...as i say, i doubt ni will appear in too many codebases, even if gets wider use)

@stevengj
Copy link
Member

stevengj commented Dec 1, 2020

ni is cute, but it's not a great antonym for in — it would be pretty confusing to most people if they saw that appearing in code, I think. And since it's not infix, it's not really symmetrical with in (and we can't make it infix because that would involve introducing a breaking new keyword).

@oxinabox
Copy link
Contributor

oxinabox commented Dec 2, 2020

We could always say the ASCII form is xs->in(x,xs)
Like we do for not in, and used to do for compose

@JeffBezanson
Copy link
Sponsor Member Author

Ok, I don't insist on ni. has is ok, or I could just delete ni for now to get the rest of this in.

@StefanKarpinski
Copy link
Sponsor Member

or I could just delete ni for now to get the rest of this in.

Let's just do that for now and open a separate issue for whether we need an ASCII name for .

@JeffBezanson JeffBezanson changed the title RFC: add ni and partially-applied versions of ∋, ∉, ∌, occursin add partially-applied versions of ∋, ∉, ∌, occursin Dec 3, 2020
@JeffBezanson JeffBezanson removed the status:triage This should be discussed on a triage call label Dec 4, 2020
@JeffBezanson JeffBezanson merged commit ef6ef82 into master Dec 7, 2020
@JeffBezanson JeffBezanson deleted the jb/partialni branch December 7, 2020 23:52
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants