applicable

applicable(f, args...) -> Bool

Determine whether the given generic function has a method applicable to the given arguments.

julia> function f(x, y)
           x + y
       end;

julia> applicable(f, 1)
false

julia> applicable(f, 1, 2)
true

Examples

  1. Check if function f is applicable to a single argument:

    julia> function f(x, y)
              x + y
          end;
    
    julia> applicable(f, 1)
    false

    In this example, the function f expects two arguments, but only one is provided. Therefore, it is not applicable.

  2. Check if function f is applicable to multiple arguments:
    julia> applicable(f, 1, 2)
    true

    Here, the function f is applicable since it can accept two arguments.

Common mistake example:

julia> applicable(f, "hello", 2)
ERROR: MethodError: no method matching f(::String, ::Int64)

In this example, the function f does not have a method defined to handle a combination of a string and an integer. It's important to ensure that the arguments provided match the expected argument types for the function to avoid such errors.

See Also

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: