Skip to content

Commit f8cecbd

Browse files
committed
Add SearchResults.append and SearchResults.prepend
1 parent 7e5500f commit f8cecbd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Lib/SearchResults.elm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Lib.SearchResults exposing
22
( Matches
33
, SearchResults(..)
4+
, append
45
, cycleNext
56
, cyclePrev
67
, empty
@@ -17,6 +18,7 @@ module Lib.SearchResults exposing
1718
, mapToList
1819
, matchesToList
1920
, next
21+
, prepend
2022
, prev
2123
, toList
2224
, toMaybe
@@ -128,6 +130,32 @@ toList results =
128130
matchesToList matches
129131

130132

133+
append : SearchResults a -> List a -> SearchResults a
134+
append results new =
135+
case results of
136+
Empty ->
137+
fromList new
138+
139+
SearchResults old ->
140+
old
141+
|> matchesToList
142+
|> (\old_ -> old_ ++ new)
143+
|> fromList
144+
145+
146+
prepend : SearchResults a -> List a -> SearchResults a
147+
prepend results new =
148+
case results of
149+
Empty ->
150+
fromList new
151+
152+
SearchResults old ->
153+
old
154+
|> matchesToList
155+
|> (\old_ -> new ++ old_)
156+
|> fromList
157+
158+
131159
next : SearchResults a -> SearchResults a
132160
next =
133161
map nextMatch

0 commit comments

Comments
 (0)