|
4 | 4 | # and the values are arrays of elements in the collection that correspond to the key. |
5 | 5 | Puppet::Functions.create_function(:group_by) do |
6 | 6 | # @param collection A collection of things to group. |
7 | | - # @example Group array of strings by length, results in e.g. { 1 => [a, b], 2 => [ab] } |
| 7 | + # @example Group array of strings by length, results in e.g. `{ 1 => [a, b], 2 => [ab] }` |
| 8 | + # ```puppet |
8 | 9 | # [a, b, ab].group_by |$s| { $s.length } |
9 | | - # @example Group array of strings by length and index, results in e.g. {1 => ['a'], 2 => ['b', 'ab']} |
| 10 | + # ``` |
| 11 | + # @example Group array of strings by length and index, results in e.g. `{1 => ['a'], 2 => ['b', 'ab']}` |
| 12 | + # ```puppet |
10 | 13 | # [a, b, ab].group_by |$i, $s| { $i%2 + $s.length } |
11 | | - # @example Group hash iterating by key-value pair, results in e.g. { 2 => [['a', [1, 2]]], 1 => [['b', [1]]] } |
| 14 | + # ``` |
| 15 | + # @example Group hash iterating by key-value pair, results in e.g. `{ 2 => [['a', [1, 2]]], 1 => [['b', [1]]] }` |
| 16 | + # ```puppet |
12 | 17 | # { a => [1, 2], b => [1] }.group_by |$kv| { $kv[1].length } |
13 | | - # @example Group hash iterating by key and value, results in e.g. { 2 => [['a', [1, 2]]], 1 => [['b', [1]]] } |
14 | | - # { a => [1, 2], b => [1] }.group_by |$k, $v| { $v.length } |
| 18 | + # ``` |
| 19 | + # @example Group hash iterating by key and value, results in e.g. `{ 2 => [['a', [1, 2]]], 1 => [['b', [1]]] }` |
| 20 | + # ```puppet |
| 21 | + # { a => [1, 2], b => [1] }.group_by |$k, $v| { $v.length } |
| 22 | + # ``` |
15 | 23 | dispatch :group_by_1 do |
16 | 24 | required_param 'Collection', :collection |
17 | 25 | block_param 'Callable[1,1]', :block |
|
0 commit comments