FilterHelpers.jl

A place to add some missing filter functions: filterfirst, filtersingle, filterlast, etc.
Author bradcarman
Popularity
1 Star
Updated Last
1 Year Ago
Started In
October 2022

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`

Required Packages

No packages found.

Used By Packages