MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 2 | <object|lwobject>** unique_array(<object|lwobject> *obarr |
| 3 | , string|closure fun) |
| 4 | <object|lwobject>** unique_array(<object|lwobject> *obarr |
| 5 | , string|closure fun, mixed skip) |
| 6 | <object|lwobject>** unique_array(<object|lwobject> *obarr |
| 7 | , string|closure fun, mixed extra... |
| 8 | , mixed skip) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 9 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 10 | DESCRIPTION |
| 11 | Groups objects together for which the separator function returns the |
| 12 | same value. obarr should be an array of objects, other types are |
| 13 | ignored. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 14 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 15 | If the separator function is defined by name, it is searched and |
| 16 | called in the objects from <obarr>. If <extra> arguments are given, |
| 17 | they are passed to the function as arguments. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 18 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 19 | If the separator function is defined as a closure, it will be passed |
| 20 | the objects from <obarr> as first argument, with the <extra> arguments |
| 21 | (if any) passed following. |
| 22 | |
| 23 | If the <skip> argument is given (it is required when <extra> arguments |
| 24 | are to be used), and the return value from the separator function call |
| 25 | matches this value, the object in question will _not_ be included in |
| 26 | the returned array. Default value for <skip> is the number 0. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 27 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 28 | The returned array is an array of arrays of objects in the form: |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 29 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 30 | ({ ({ Same1:1, Same1:2, ... Same1:N }), |
| 31 | ({ Same2:1, Same2:2, ... Same2:N }), |
| 32 | .... |
| 33 | ({ SameM:1, SameM:2, ... SameM:N }) }) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 34 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 35 | EXAMPLES |
| 36 | mixed *arr; |
| 37 | arr=unique_array(users(), "_query_level", -1); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 38 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 39 | This will return an array of arrays holding all user objects |
| 40 | grouped together by their user levels. Wizards have a user |
| 41 | level of -1 so they will not appear in the the returned array. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 42 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 43 | HISTORY |
| 44 | LDMud 3.3 added the possibility to call closures, and to |
| 45 | pass extra arguments to the separator function. |
| 46 | |
| 47 | SEE ALSO |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 48 | filter(E), map(E) |