Skip to content

Commit

Permalink
feat: use && filters for documented
Browse files Browse the repository at this point in the history
  • Loading branch information
ghivert committed Jul 17, 2024
1 parent 844880c commit a5ad049
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions apps/frontend/src/data/model.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn update_search_results(
pub fn update_search_results_filter(model: Model) {
let default_key =
model.submitted_input <> string.inspect([False, False, False, False])
let filters =
let or_filters =
[
#(model.keep_functions, fn(s: search_result.SearchResult) {
s.kind == kind.Function
Expand All @@ -123,15 +123,26 @@ pub fn update_search_results_filter(model: Model) {
#(model.keep_aliases, fn(s: search_result.SearchResult) {
s.kind == kind.TypeAlias
}),
]
|> list.filter(fn(a) { a.0 })
|> list.map(pair.second)
let and_filters =
[
#(model.keep_documented, fn(s: search_result.SearchResult) {
string.length(s.documentation) > 0
}),
]
|> list.filter(fn(a) { a.0 })
|> list.map(pair.second)
let filter = fn(s) {
use <- bool.guard(when: list.is_empty(filters), return: True)
list.any(filters, function.apply1(_, s))
case list.is_empty(or_filters) {
True -> True
False -> list.any(or_filters, function.apply1(_, s))
}
&& case list.is_empty(and_filters) {
True -> True
False -> list.any(and_filters, function.apply1(_, s))
}
}
let key =
model.submitted_input
Expand Down

0 comments on commit a5ad049

Please sign in to comment.