Use strings of a list to use in List.any on another list

Is there a way that I could make a list instead of adding || operator for every new case?

iconSpriteHasColorOfRat entry &&
(entry.textsLeftToRight |> List.any (String.toLower >> String.contains "traitor"))
        || (entry.textsLeftToRight |> List.any (String.toLower >> String.contains "hastatus"))
        || (entry.textsLeftToRight |> List.any (String.toLower >> String.contains "misthios"))
        || (entry.textsLeftToRight |> List.any (String.toLower >> String.contains "nauclarius"))
        || (entry.textsLeftToRight |> List.any (String.toLower >> String.contains "transport"))
        || (entry.textsLeftToRight |> List.any (String.toLower >> String.contains "silencer"))

Using (List.any string.contain) on entry.textLeftToRight with strings of triggerList and see if there is a match?

triggerList : List String
triggerList =
    [ "hastatus"
    , "misthios"
    , "nauclarius"
    , "transport"
    , "silencer"
    , "ascriber"
    , "eraser"
    , "abolisher"
    ]

I’m not sure I’m being clear but if I come up with a different explanation I will edit.

Yes, that works. You can write it like this:

entryTriggers entry =
    iconSpriteHasColorOfRat entry && entryTextTriggers entry


entryTextTriggers entry =
    triggerList
        |> List.any
            (\trigger ->
                entry.textsLeftToRight
                    |> List.any (String.toLower >> String.contains trigger)
            )

Here is a complete program to test that function on different entries:
https://elm-editor.com/?project-state-deflate-base64=rVbbkppKFP0XX5NKIUoSUnUelBmx8ZIRlUtPpVLQGEQbpMYrTs2%2Fn9WAis5x8nIedindu%2Fd17dX9WtvNXtbRKvktS7L0uy7XfrzWJi%2Bz2XAVzGo%2Fnp%2BfazMef1msV0nt82utzVd%2BufNaa63b3nr2tVn7UZvtVyHRWiFJTIXp0%2Bhn1Ipcp733db5wHTP15WbUb510hrvAMRZ0XF96jsHdhrljMecsI19JZ93LdQqJWMNYkLA454z35Z7BfV3aBLGVMZnv%2FAjnNLLvLx4VyMVPbHKmW1sKceXSfvfaPtV5Ru2hRBar8JzDRbDf2dKYHz092Pn6aOfGnSOduFLfNpRAt47iHFk8bgda80iiU3wVia21P1YjFqsNJltZRT%2F7SH%2FmIHYRr0YO%2FUVr%2B1Mjay3CvtA5S16HnSurGR1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