Clarity.Graph.Filter (Clarity v0.4.0)
View SourceComposable filter functions for graph vertices.
Filters are higher-order functions that take a graph for preparation and return a predicate function that can be called for each vertex.
Example Usage
# Single filter
subgraph = Graph.filter(graph, Filter.within_steps(vertex, 2, 1))
# Composed filters
filters = [
Filter.within_steps(vertex, 2, 1),
Filter.reachable_from(root_vertex),
Filter.custom(fn v -> String.contains?(Vertex.name(v), "MyApp") end)
]
subgraph = Graph.filter(graph, filters)
Summary
Functions
Combines multiple filters using AND logic.
Combines multiple filters using OR logic.
Negates a filter using NOT logic.
Creates a filter that includes vertices reachable from any of the specified vertices.
Creates a filter that includes only vertices of the specified types.
Creates a filter that includes vertices within the specified number of steps from a center vertex.
Types
@type filter() :: Clarity.Graph.query() | (Clarity.Graph.t() -> Clarity.Graph.query())
Functions
Combines multiple filters using AND logic.
A vertex must pass ALL filters to be included in the result.
Examples
Filter.all([
Filter.within_steps(vertex, 2, 0),
Filter.vertex_type([Module])
])
Combines multiple filters using OR logic.
A vertex must pass ANY of the filters to be included in the result.
Examples
Filter.any([
Filter.vertex_type([Module]),
Filter.vertex_type([Application])
])
Negates a filter using NOT logic.
A vertex must NOT pass the filter to be included in the result.
Examples
# Everything except modules
Filter.negate(Filter.vertex_type([Module]))
@spec reachable_from([Clarity.Vertex.t()]) :: filter()
Creates a filter that includes vertices reachable from any of the specified vertices.
Creates a filter that includes only vertices of the specified types.
Takes a list of modules (struct types) and includes only vertices whose
__struct__ field matches one of the specified types.
Examples
# Only application vertices
Filter.vertex_type([Clarity.Vertex.Application])
# Only modules and applications
Filter.vertex_type([Clarity.Vertex.Module, Clarity.Vertex.Application])
@spec within_steps(Clarity.Vertex.t(), non_neg_integer(), non_neg_integer()) :: filter()
Creates a filter that includes vertices within the specified number of steps from a center vertex.
This filter includes vertices reachable within max_outgoing_steps forward hops
OR max_incoming_steps backward hops from the center vertex.