blob: b1c649cd9c53b921206a28a0e4a9bbcbe301d702 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
Zesstra715ec202025-07-09 22:18:31 +02002 <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 User88f12472016-06-24 23:31:02 +02009
Zesstra715ec202025-07-09 22:18:31 +020010DESCRIPTION
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 User88f12472016-06-24 23:31:02 +020014
Zesstra715ec202025-07-09 22:18:31 +020015 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 User88f12472016-06-24 23:31:02 +020018
Zesstra715ec202025-07-09 22:18:31 +020019 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 User88f12472016-06-24 23:31:02 +020027
Zesstra715ec202025-07-09 22:18:31 +020028 The returned array is an array of arrays of objects in the form:
MG Mud User88f12472016-06-24 23:31:02 +020029
Zesstra715ec202025-07-09 22:18:31 +020030 ({ ({ Same1:1, Same1:2, ... Same1:N }),
31 ({ Same2:1, Same2:2, ... Same2:N }),
32 ....
33 ({ SameM:1, SameM:2, ... SameM:N }) })
MG Mud User88f12472016-06-24 23:31:02 +020034
Zesstra715ec202025-07-09 22:18:31 +020035EXAMPLES
36 mixed *arr;
37 arr=unique_array(users(), "_query_level", -1);
MG Mud User88f12472016-06-24 23:31:02 +020038
Zesstra715ec202025-07-09 22:18:31 +020039 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 User88f12472016-06-24 23:31:02 +020042
Zesstra715ec202025-07-09 22:18:31 +020043HISTORY
44 LDMud 3.3 added the possibility to call closures, and to
45 pass extra arguments to the separator function.
46
47SEE ALSO
Zesstrad59c3892019-11-28 20:53:39 +010048 filter(E), map(E)