File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ module Lib.Search exposing
4
4
, debounce
5
5
, debounce_
6
6
, empty
7
+ , fromList
7
8
, fromResult
8
9
, hasSubstantialQuery
9
10
, isEmptyQuery
@@ -64,6 +65,11 @@ search query_ =
64
65
NotAsked query_
65
66
66
67
68
+ fromList : String -> List a -> Search a
69
+ fromList q matches =
70
+ Success q ( SearchResults . fromList matches)
71
+
72
+
67
73
68
74
-- TRANSFORM
69
75
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ module Lib.SearchResults exposing
5
5
, cycleNext
6
6
, cyclePrev
7
7
, empty
8
+ , filterMatches
8
9
, focus
9
10
, focusOn
10
11
, from
@@ -110,6 +111,24 @@ mapToList f results =
110
111
mapMatchesToList f matches
111
112
112
113
114
+ filterMatches : (a -> Bool ) -> SearchResults a -> SearchResults a
115
+ filterMatches f results =
116
+ case results of
117
+ Empty ->
118
+ Empty
119
+
120
+ SearchResults ( Matches matches) ->
121
+ SearchResults
122
+ ( Matches
123
+ ( matches
124
+ |> Zipper . toList
125
+ |> List . filter f
126
+ |> Zipper . fromList
127
+ |> Maybe . withDefault matches
128
+ )
129
+ )
130
+
131
+
113
132
toMaybe : SearchResults a -> Maybe (Matches a )
114
133
toMaybe results =
115
134
case results of
You can’t perform that action at this time.
0 commit comments