Skip to content

Commit

Permalink
Clientside filtering is case insensitive now
Browse files Browse the repository at this point in the history
I really enjoy the concept of filterMap combined with Maybe.
  • Loading branch information
fidel committed Mar 22, 2024
1 parent 2bb07e6 commit a87d7f6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
18 changes: 17 additions & 1 deletion ruby_event_store-browser/elm/src/Search.elm
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,20 @@ filterStreams stream streams =
[]

else
List.filter (String.contains stream) streams
List.filterMap (caseInsensitiveContains stream) streams


caseInsensitiveContains : Stream -> Stream -> Maybe Stream
caseInsensitiveContains needle haystack =
let
needleLower =
String.toLower needle

haystackLower =
String.toLower haystack
in
if String.contains needleLower haystackLower then
Just haystack

else
Nothing
7 changes: 6 additions & 1 deletion ruby_event_store-browser/elm/tests/SearchTest.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module SearchTest exposing (suite)

import Expect
import Search exposing (Stream, filterStreams)
import Search exposing (filterStreams)
import Test exposing (..)


Expand Down Expand Up @@ -29,5 +29,10 @@ suite =
Expect.equal
[ "DummyStream$78" ]
(filterStreams "78" [ "DummyStream$78", "DummyStream$79" ])
, test "filterStreams is case insensitive" <|
\_ ->
Expect.equal
[ "DummyStream$78", "DummyStream$79" ]
(filterStreams "stream" [ "DummyStream$78", "DummyStream$79" ])
]
]

0 comments on commit a87d7f6

Please sign in to comment.