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

Suggestion: Warn on x -> foo(x) #342

Open
jakobnissen opened this issue Aug 15, 2022 · 3 comments
Open

Suggestion: Warn on x -> foo(x) #342

jakobnissen opened this issue Aug 15, 2022 · 3 comments

Comments

@jakobnissen
Copy link

It's common to see people do e.g. filter(i -> isodd(i), arr). This is unidiomatic and should be filter(isodd, arr). It seems like it should be easy to add to the linter.

@nsajko
Copy link
Contributor

nsajko commented Oct 11, 2022

I think this problem may not be as easy as it seems at first hand, because any type may be callable in Julia and the proposed suggestion only makes sense in general for Function subtypes.

For example:

julia> struct S end

julia> (::S)() = 3

julia> s = S()
S()

julia> f = (() -> s())
#1 (generic function with 1 method)

julia> s() == f()
true

julia> s isa Function
false

julia> f isa Function
true

Docs: https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects

@pfitzseb
Copy link
Member

This is only relevant when the higher order function the functor is passed to has a strict type constraints on Function (instead of e.g. Base.Callable).

@nsajko
Copy link
Contributor

nsajko commented Oct 11, 2022

This is only relevant when the higher order function the functor is passed to has a strict type constraints on Function

Yes, but this isn't "only" as far as I see. Furthermore, the constraint doesn't need to be on the direct callee - you'd have to check all potential indirect callees for such constraints.

instead of e.g. Base.Callable

Base.Callable is completely undocumented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants