Created
January 31, 2026 16:05
-
-
Save ncalm/f178e50fcf74781351179802741b60cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Check if one or all values of a list are contained in a text string | |
| txt: the text string to check against | |
| values: a list of substrings, each of which is tested to see if it is found in txt | |
| switch: either List.AnyTrue or List.AllTrue depending on whether you want to check whether at least one of values is contained in txt or if all values are contained in txt | |
| */ | |
| (txt as text, values as list, switch as function) as logical => | |
| let | |
| check_values_non_empty = | |
| if List.IsEmpty(values) | |
| then error Error.Record("ArgumentError", "values must be a non-empty list", | |
| [Argument = "values", Received = "{}"]) | |
| else true, | |
| check_function_type = | |
| if not List.Contains({List.AnyTrue,List.AllTrue},switch) | |
| then error Error.Record("ArgumentError", "Invalid function passed to switch", | |
| [Argument = "switch", | |
| Allowed = "Either List.AnyTrue or List.AllTrue", | |
| Received = try Value.Expression(Value.Optimize(switch))[Name] otherwise "<unknown function>" ]) | |
| else true, | |
| flags = List.Transform(values, each Text.Contains(txt, _)) | |
| in | |
| if check_values_non_empty and check_function_type then switch(flags) else null, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment