liveBook · Manning

Custom filter function

As explained in API Design Patterns

A custom filter function is a predefined callable extension of filter syntax that performs a narrowly controlled operation.

A custom filter function is a narrowly scoped callable added to filter expressions when native syntax cannot safely express a required operation. It provides controlled flexibility without permitting arbitrary code, external data access, or unrestricted computation. section 22.3.2

Prefer a custom function when:

  • A resource needs matching by a string prefix or suffix rather than exact equality. section 22.3.2
  • A wildcard extension would introduce escaping and syntax-complexity problems. section 22.3.2
  • One exceptional operation needs more computation, but arbitrary expressions would be unsafe or too expensive. section 22.3.2

String matching without wildcard syntax

Instead of extending equality with patterns such as title = "*(new)", expose a predefined helper for prefix or suffix matching. Keep the operation explicit and constrained rather than accepting amended syntax or arbitrary code. section 22.3.2

How API Design Patterns covers it

How deep it goes
Defines the design rationale and boundaries but does not specify a concrete function grammar or implementation.
Examples
Uses prefix and suffix matching, wildcard syntax, and numeric-string comparison as motivating cases.
What it assumes
Assumes familiarity with filter expressions and resource conditions while clarifying why arbitrary computation requires restriction.
What you can do after
Evaluate filter-extension designs by balancing user flexibility, syntax complexity, computation cost, and safety.
How it connects
Connects filtering syntax with expressions, wildcard matching, arbitrary code execution, and type coercion.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.