Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 1.21 KB

README.md

File metadata and controls

26 lines (19 loc) · 1.21 KB

FilterHelpers.jl

Build Status Coverage

This package provides some simple functions I often find I would like to have in the Julia language, similar to the find functions (i.e. findfirst, findlast, etc.), which return the object rather than the index. This also includes filtersingle which provides the same functionality as c# Enumerable.Single method.

For example:

    struct Person
        id::Int
        name::String
    end

    brad = Person(1, "Brad")
    julia = Person(1, "Julia")
    audra = Person(2, "Audra")
    ellie = Person(3, "Ellie")

    people = [brad, audra, ellie, julia]

    x = filtersingle(x->x.id == 3, people) #returns the object `ellie`
    x = filtersingle(x->x.id == 1, people) #throws an exception
    x = filterfirst(x->x.id == 1, people) #returns `brad`