|
| 1 | +let |
| 2 | + // expects a list of pairs of 2 elements, first is the digit, 2nd is the unit |
| 3 | + |
| 4 | + List.SelectBySuffix.Func = ( items as list, unit as text ) as any => |
| 5 | + List.First( |
| 6 | + List.Select( items, |
| 7 | + (i) => i{1} = unit ), null ){0}?, |
| 8 | + |
| 9 | + List.SelectBySuffix.Type = type function ( |
| 10 | + items as (type { text }), |
| 11 | + unit as text |
| 12 | + ) as text meta [ |
| 13 | + Documentation.Name = "List.SelectBySuffix", |
| 14 | + Documentation.LongDescription = Text.Combine({ |
| 15 | + "After calling <code>Splitter.SplitDigitWithSuffix()</code>, this function will choose one item from the pair", "", "#(tab)<b>Example</b>: For the text <code>'2m 3s'</code> find <code>'2'<code> if unit is <code>'m'<code>" |
| 16 | + }, "<br>"), |
| 17 | + Documentation.Examples = { |
| 18 | + [ |
| 19 | + Description = "Selects the first item in a list that ends with the specified suffix", |
| 20 | + Code = Format.DocExpand( "List.SelectBySuffix( { {␞2␞, ␞d␞}, {␞3␞, ␞h␞} }, ␞h␞)" ), |
| 21 | + Result = Format.DocExpand("3") |
| 22 | + ], |
| 23 | + [ |
| 24 | + Description = "Selects the first item in a list that ends with the specified suffix", |
| 25 | + Code = Format.DocExpand( "List.SelectBySuffix( { {␞2␞, ␞d␞}, {␞3␞, ␞h␞} }, ␞d␞)" ), |
| 26 | + Result = Format.DocExpand("2") |
| 27 | + ] |
| 28 | + } |
| 29 | + ] |
| 30 | + in |
| 31 | + Value.ReplaceType( List.SelectBySuffix.Func, List.SelectBySuffix.Type ) |
| 32 | + |
0 commit comments