-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathText.AnyMatches.pq
More file actions
37 lines (36 loc) · 1.38 KB
/
Text.AnyMatches.pq
File metadata and controls
37 lines (36 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
let
/*
For a list of values, test any combination of: Text.StartsWith, Text.Contains, Text.EndsWith
one or more matches returns true
future:
List.Generate/Accumulate to stop calls when one is already true
*/
#"Text.AnyMatch" = (
source as text,
optional filtersStartsWith as nullable list,
optional filterContainsWith as nullable list,
optional filterEndsWith as nullable list,
optional comparer as nullable function
) as logical =>
let
comparer = comparer ?? Comparer.OrdinalIgnoreCase,
filtersStartsWith = filtersStartsWith ?? {},
filterContainsWith = filterContainsWith ?? {},
filterEndsWith = filterEndsWith ?? {},
// x = FilterPrefix Text.Contains(source, Config),
anyStart = List.Transform(
filtersStartsWith, (i) => Text.StartsWith( source, i, comparer)
),
anyContain = List.Transform(
filterContainsWith, (i) => Text.Contains( source, i, comparer)
),
anyEnd = List.Transform(
filterEndsWith, (i) => Text.EndsWith( source, i, comparer)
),
boolShouldFilter = List.AnyTrue( anyStart )
or List.AnyTrue( anyContain )
or List.AnyTrue( anyEnd )
in
boolShouldFilter
in
#"Text.AnyMatch"