I’m adding a filter for certain types of asteroids, and it works with one item but with either space or comma separated values, it isn’t picking it up - if I want to filter multiple asteroid types, how do I do this?
Welcome Alan
So an example would be you want to include both “Veldspar” and “Scordite”.
Here is how you could do that:
First, declare a function like this to support filtering:
type alias BotSettings =
{ includeAsteroidPatterns : List String
}
asteroidOverviewEntryMatchesSettings : BotSettings -> OverviewWindowEntry -> Bool
asteroidOverviewEntryMatchesSettings settings overviewEntry =
let
textMatchesPattern text =
(settings.includeAsteroidPatterns == [])
|| (settings.includeAsteroidPatterns
|> List.any (\pattern -> String.contains (String.toLower pattern) (String.toLower text))
)
in
overviewEntry.cellsTexts
|> Dict.values
|> List.any textMatchesPattern
Then, in the place where you want to use the criteria, apply that function like this:
asteroidOverviewEntryMatchesSettings { includeAsteroidPatterns = [ "Veldspar", "Scordite" ] }
When you have a concrete list to filter, coming from an overview window, you can combine it with List.filter
:
List.filter
(asteroidOverviewEntryMatchesSettings { includeAsteroidPatterns = [ "Veldspar", "Scordite" ] })
listOfOverviewEntries