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

**URL:** <https://discourse.julialang.org/t/what-exactly-is-the-meaning-of-this-one-line-code-written-in-julia/24185>\
**Category:** General Usage\
**Created:** [May 13, 2019, 6:57pm UTC](https://discourse.julialang.org/t/what-exactly-is-the-meaning-of-this-one-line-code-written-in-julia/24185 "2019-05-13T18:57:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [May 13, 2019, 6:57pm UTC](https://discourse.julialang.org/t/what-exactly-is-the-meaning-of-this-one-line-code-written-in-julia/24185/1 "2019-05-13T18:57:34Z")

</div>

`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?

---

<div class="post-metadata">

**Author:** ![shorty66](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shorty66/32/3254_2.png) [@shorty66](https://discourse.julialang.org/u/shorty66)\
**Post date:** [May 13, 2019, 7:04pm UTC](https://discourse.julialang.org/t/what-exactly-is-the-meaning-of-this-one-line-code-written-in-julia/24185/2 "2019-05-13T19:04:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Vasily\_Pisarev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vasily_pisarev/32/7929_2.png) [@Vasily\_Pisarev](https://discourse.julialang.org/u/Vasily_Pisarev)\
**Post date:** [May 13, 2019, 7:06pm UTC](https://discourse.julialang.org/t/what-exactly-is-the-meaning-of-this-one-line-code-written-in-julia/24185/3 "2019-05-13T19:06:06Z")

</div>

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

```julia
function foo(e)
    e.time >= event.time
end

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 13, 2019, 7:29pm UTC](https://discourse.julialang.org/t/what-exactly-is-the-meaning-of-this-one-line-code-written-in-julia/24185/4 "2019-05-13T19:29:54Z")

</div>

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).
> 
> Examples  
> ≡≡≡≡≡≡≡≡≡≡
> 
> A = [1, 2, 3, 4]  
> 4-element Array{Int64,1}:  
> 1  
> 2  
> 3  
> 4

> findlast(isodd, A)  
> 3

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.
