Skip to content

Commit

Permalink
Require filter function as first argument in make_selector
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Oct 29, 2024
1 parent 22e33e4 commit b29ce9e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
13 changes: 0 additions & 13 deletions src/component_selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,19 +326,6 @@ FilterComponentSelector(
string(filter_func) * COMPONENT_NAME_DELIMITER * subtype_to_string(component_type),
)

# Could try to validate filter_func here, probably not worth it
# Signature 1: put the type first for consistency with many other `make_selector` methods
"""
Make a ComponentSelector from a filter function and a type of component. The filter function
must accept instances of `component_type` as a sole argument and return a `Bool`. Optionally
provide a name and/or grouping behavior for the `ComponentSelector`.
"""
make_selector(
component_type::Type{<:InfrastructureSystemsComponent},
filter_func::Function;
groupby::Union{Symbol, Function} = :all, name::Union{String, Nothing} = nothing,
) = FilterComponentSelector(component_type, filter_func, groupby, name)

# Signature 2: put the filter function first for consistency with non-`ComponentSelector` `get_components`
"""
Make a ComponentSelector from a filter function and a type of component. The filter function
Expand Down
9 changes: 4 additions & 5 deletions test/test_component_selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,10 @@ end
) == named_test_filter_ent

# Construction
@test IS.make_selector(IS.TestComponent, val_over_ten) == test_filter_ent
@test IS.make_selector(val_over_ten, IS.TestComponent) == test_filter_ent
@test IS.make_selector(IS.TestComponent, val_over_ten; name = "TCOverTen") ==
@test IS.make_selector(val_over_ten, IS.TestComponent; name = "TCOverTen") ==
named_test_filter_ent
@test IS.make_selector(IS.TestComponent, val_over_ten; groupby = string) isa
@test IS.make_selector(val_over_ten, IS.TestComponent; groupby = string) isa
IS.FilterComponentSelector

# Naming
Expand All @@ -228,12 +227,12 @@ end

@test collect(
get_components_rt(
IS.make_selector(IS.SimpleTestComponent, x -> true),
IS.make_selector(x -> true, IS.SimpleTestComponent),
test_sys,
)) == Vector{IS.InfrastructureSystemsComponent}()
@test collect(
get_components_rt(
IS.make_selector(IS.InfrastructureSystemsComponent, x -> false),
IS.make_selector(x -> false, IS.InfrastructureSystemsComponent),
test_sys,
)) == Vector{IS.InfrastructureSystemsComponent}()
the_components = get_components_rt(test_filter_ent, test_sys)
Expand Down

0 comments on commit b29ce9e

Please sign in to comment.