What exactly is the meaning of this one line code written in Julia?

findlast(e -> e.time >= event.time, eventList)
I understand that the findlast(A) function will return the index or key of the last true value in A. It will return nothing if there is no true value in A.
What I do not quite understand is the exact meaning inside of the parenthesis. I know that eventList is a vector of events. event inside of the parenthesis is a specific element of the vector eventList. So I guess the stuff inside of the parenthesis will go through each element of the vector eventList, and compare the time attributes with the specific element event, and return either true or false. So, the stuff inside of the parenthesis is a vector of boolean values. findlast will return the last index of this vector which is a true value. Is this correct?

This is about correct. What is called here is the findlast(predicate, A) version of the function. Remember that julia uses multiple dispatch to determine the method which is called depending on all the arguments of the function.

In this case, the first argument is an anonymus function e -> e.time >= event.time which compares if the time variable of each instance of e is larger than the time variable of event.

This anonymous function will be called on every element of eventList to determine a boolean value. Findlast returns the last true value of that vector.


Find the index of the last element e in eventList that satisfies the condition e.time >= event.time.
e -> e.time >= event.time is an anonymous function equivalent to the named

function foo(e)
    e.time >= event.time
1 Like

Almost entirely correct. What you missed is that function findlast has more than a method, so the one you are calling is not the one with signature findlast(A) but the one with the following documentation on:

findlast(predicate::Function, A)
Return the index or key of the last element of A for which predicate returns true.
Return nothing if there is no such element.
Indices or keys are of the same type as those returned by keys(A) and pairs(A).


A = [1, 2, 3, 4]
4-element Array{Int64,1}:

findlast(isodd, A)

Note that documentation for all methods of function findlast are available by typing ?findlast in the REPL, and using @which findlast(e -> e.time >= event.time, eventList) would have given you the signature of the method that is being called.