File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ module Lib.SearchResults exposing
21
21
, next
22
22
, prepend
23
23
, prev
24
+ , take
24
25
, toList
25
26
, toMaybe
26
27
, uniqueMatchesBy
@@ -102,6 +103,26 @@ mapMatches f results =
102
103
SearchResults ( Matches ( Zipper . map f matches))
103
104
104
105
106
+ {- | Limit the number of results
107
+ -}
108
+ take : Int -> SearchResults a -> SearchResults a
109
+ take n results =
110
+ case results of
111
+ Empty ->
112
+ Empty
113
+
114
+ SearchResults ( Matches matches) ->
115
+ SearchResults
116
+ ( Matches
117
+ ( matches
118
+ |> Zipper . toList
119
+ |> List . take n
120
+ |> Zipper . fromList
121
+ |> Maybe . withDefault matches
122
+ )
123
+ )
124
+
125
+
105
126
mapToList : (a -> Bool -> b ) -> SearchResults a -> List b
106
127
mapToList f results =
107
128
case results of
You can’t perform that action at this time.
0 commit comments