blib/lib/Venus/Set.pm

filter: Statementstmt 95.9% 399 / 416 Branchbran 67.5% 108 / 160 Conditioncond 58.3% 28 / 48 MC/DCmcdc 43.3% 13 / 30 Subroutinesub 90.0% 72 / 80 Podpod 74.6% 50 / 67 totaltotal 83.6% 670 / 801 CC 121 SCAR 22.5
CC
121
Cov
86%
superset
57.8
subset
31.9
difference
9.1
CRAP 9.5
« blib/lib/Venus/Collect.pm ↑ Summary blib/lib/Venus/Map.pm »
1 package Venus::Set;
2  
3 3 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 3 ▶use Venus::Class 'attr', 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INHERITS
13  
14 3 base 'Venus::Kind::Utility';
15  
16 # INTEGRATES
17  
18 3 with 'Venus::Role::Mappable';
19 3 with 'Venus::Role::Encaseable';
20  
21 # ATTRIBUTES
22  
23 3 attr 'accept';
24  
25 # BUILDERS
26  
27 122 ▶sub build_arg {
Subroutine build_arg: called CC=1 SCAR=0.0
Pod undocumented
28 122 my ($self, $data) = @_;
29  
30 return {
31 122 value => $data,
32 };
33 }
34  
35 144 ▶sub build_args {
Subroutine build_args: called CC=2 SCAR=6.9
Pod undocumented
36 144 my ($self, $data) = @_;
37  
38 144 ▶ $data->{accept} ||= 'any';
Condition100%2/2
$data->{"accept"} ||= "any"
l!l
4140
MC/DC100%1/1
$data->{"accept"} ||= "any"
$data->{"accept"}
Truth table100%2/2
A
A= $data->{"accept"}
Aresult
11
00
39  
40 144 return $data;
41 }
42  
43 144 ▶sub build_self {
Subroutine build_self: called CC=2 SCAR=6.9
Pod undocumented
44 144 my ($self, $data) = @_;
45  
46 144 my $value = delete $self->{value};
47  
48 144 ▶ $self->push(@$value) if ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 127 17 144
49  
50 144 return $self;
51 }
52  
53 # METHODS
54  
55 2 ▶sub all {
Subroutine all: called CC=6 SCAR=18.3
Pod documented
56 2 my ($self, $code) = @_;
57  
58 2 my $data = $self->get;
59  
60 2 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 2 2
61  
62 2 my $failed = 0;
63  
64 2 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 18 2 20
65 18 my $index = $i;
66 18 my $value = $data->[$i];
67  
68 18 local $_ = $value;
69 18 ▶ $failed++ if !$code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
unless &$code($index, $value) 0 18 18
70  
71 18 ▶ CORE::last if $failed;
Branch: 1 branch
BranchTrueFalseTotal
if $failed 0 18 18
72 }
73  
74 2 ▶ return $failed ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
$failed ? : 0 2 2
75 }
76  
77 2 ▶sub any {
Subroutine any: called CC=6 SCAR=18.1
Pod documented
78 2 my ($self, $code) = @_;
79  
80 2 my $data = $self->get;
81  
82 2 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 2 2
83  
84 2 my $found = 0;
85  
86 2 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 10 0 10
87 10 my $index = $i;
88 10 my $value = $data->[$i];
89  
90 10 local $_ = $value;
91 10 ▶ $found++ if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 2 8 10
92  
93 10 ▶ CORE::last if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 2 8 10
94 }
95  
96 2 ▶ return $found ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 2 0 2
97 }
98  
99 4 ▶sub attest {
Subroutine attest: called CC=1 SCAR=0.0
Pod documented
100 4 my ($self) = @_;
101  
102 4 require Venus::Assert;
103  
104 4 my $assert = Venus::Assert->new;
105  
106 4 my $accept = $self->accept;
107  
108 4 $assert->expression("within[arrayref, $accept]");
109  
110 4 return $assert->result($self->get);
111 }
112  
113 2 ▶sub call {
Subroutine call: called CC=1 SCAR=0.0
Pod documented
114 2 my ($self, $mapper, $method, @args) = @_;
115  
116 2 require Venus::What;
117  
118 18 ▶ return $self->$mapper(sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
119 18 my ($key, $val) = @_;
120  
121 18 my $what = Venus::What->new($val)->deduce;
122  
123 18 local $_ = $what;
124  
125 18 $what->$method(@args)
126 2 });
127 }
128  
129 88 ▶sub contains {
Subroutine contains: called CC=3 SCAR=11.1
Pod documented
130 88 my ($self, $value) = @_;
131  
132 88 my $value_to_object = $self->value_to_object($value);
133  
134 88 my $value_to_digest = $self->value_to_digest($value_to_object);
135 88 my $index_by_digest = $self->index_by_digest;
136  
137 88 ▶ if (exists $index_by_digest->{$value_to_digest}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $index_by_digest->{$value_to_digest}) 73 15 88
138 73 return true;
139 }
140  
141 15 my $value_to_refaddr = $self->value_to_refaddr($value_to_object);
142 15 my $index_by_refaddr = $self->index_by_refaddr;
143  
144 15 ▶ if (exists $index_by_refaddr->{$value_to_refaddr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $index_by_refaddr->{$value_to_refaddr}) 0 15 15
145 0 return true;
146 }
147  
148 15 return false;
149 }
150  
151 25 ▶sub count {
Subroutine count: called CC=1 SCAR=0.0
Pod documented
152 25 my ($self) = @_;
153  
154 25 my $data = $self->get;
155  
156 25 return scalar(@$data);
157 }
158  
159 1 ▶sub default {
Subroutine default: called CC=1 SCAR=0.0
Pod documented
160 1 return [];
161 }
162  
163 1 ▶sub delete {
Subroutine delete: called CC=3 SCAR=11.2
Pod documented
164 1 my ($self, $index) = @_;
165  
166 1 ▶ return undef if !$index;
Branch: 1 branch
BranchTrueFalseTotal
unless $index 0 1 1
167  
168 1 my $index_by_digest = $self->index_by_digest;
169 1 my $index_by_order = $self->index_by_order;
170  
171 1 my $value = $index_by_digest->{$index_by_order->{$index}};
172  
173 1 ▶ return undef if !defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 1 1
174  
175 1 return $self->remove($value);
176 }
177  
178 5 ▶sub difference {
Subroutine difference: called CC=9 SCAR=22.1
Pod documented
179 5 my ($self, $data) = @_;
180  
181 5 require Scalar::Util;
182  
183 5 my $set = $self->class->new;
184  
185 5 ▶ if (Scalar::Util::blessed($data) && $data->isa('Venus::Set')) {
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($data) and $data->isa('Venus::Set')) { } 1 4 5
elsif (builtin::blessed($data) and $data->isa('Venus::Array')) { } 1 3 4
elsif (ref $data eq 'ARRAY') { } 3 0 3
Condition100%3/3
builtin::blessed($data) and $data->isa("Venus::Set")
!ll&&!rl&&r
311
MC/DC100%2/2
builtin::blessed($data) and $data->isa("Venus::Set")
builtin::blessed($data) $data->isa("Venus::Set")
Truth table100%3/3
A and B
A= builtin::blessed($data)B= $data->isa("Venus::Set")
ABresult
0X0
100
111
186 1 $set->push($_) for grep !$self->contains($_), $data->list;
187 }
188 ▶ elsif (Scalar::Util::blessed($data) && $data->isa('Venus::Array')) {
Condition66%2/3
builtin::blessed($data) and $data->isa("Venus::Array")
!ll&&!rl&&r
301
MC/DC50%1/2
builtin::blessed($data) and $data->isa("Venus::Array")
builtin::blessed($data) $data->isa("Venus::Array")
Truth table66%2/3
A and B
A= builtin::blessed($data)B= $data->isa("Venus::Array")
ABresult
0X0
100
111
189 1 $set->push($_) for grep !$self->contains($_), $data->list;
190 }
191 elsif (ref($data) eq 'ARRAY') {
192 3 $set->push($_) for grep !$self->contains($_), @$data;
193 }
194  
195 5 return $set;
196 }
197  
198 2 ▶sub different {
Subroutine different: called CC=2 SCAR=6.9
Pod documented
199 2 my ($self, $data) = @_;
200  
201 2 my $set = $self->difference($data);
202  
203 2 ▶ return $set->count ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$set->count ? : 1 1 2
204 }
205  
206 2 ▶sub each {
Subroutine each: called CC=4 SCAR=13.9
Pod documented
207 2 my ($self, $code) = @_;
208  
209 2 my $data = $self->get;
210  
211 2 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 2 2
212  
213 2 my $result = [];
214  
215 2 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 18 2 20
216 18 my $index = $i;
217 18 my $value = $data->[$i];
218  
219 18 local $_ = $value;
220 18 CORE::push(@$result, $code->($index, $value));
221 }
222  
223 2 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
224 }
225  
226 1 ▶sub empty {
Subroutine empty: called CC=1 SCAR=0.0
Pod documented
227 1 my ($self) = @_;
228  
229 1 $self->reset;
230  
231 1 return $self;
232 }
233  
234 1 ▶sub exists {
Subroutine exists: called CC=2 SCAR=7.0
Pod documented
235 1 my ($self, $index) = @_;
236  
237 1 my $data = $self->get;
238  
239 1 ▶ return $index <= $#{$data} ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$index <= $#{$data;} ? : 1 0 1
240 }
241  
242 1 ▶sub first {
Subroutine first: called CC=1 SCAR=0.0
Pod documented
243 1 my ($self) = @_;
244  
245 1 return $self->get->[0];
246 }
247  
248 284 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
249 284 my ($self, @args) = @_;
250  
251 284 ▶ return $self->value if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 282 2 284
252  
253 2 my ($index) = @args;
254  
255 2 return $self->value->[$index];
256 }
257  
258 3 ▶sub grep {
Subroutine grep: called CC=5 SCAR=16.2
Pod documented
259 3 my ($self, $code) = @_;
260  
261 3 my $data = $self->get;
262  
263 3 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 3 3
264  
265 3 my $result = [];
266  
267 3 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 27 3 30
268 27 my $index = $i;
269 27 my $value = $data->[$i];
270  
271 27 local $_ = $value;
272 27 ▶ CORE::push(@$result, $value) if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 17 10 27
273 }
274  
275 3 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
276 }
277  
278 5 ▶sub head {
Subroutine head: called CC=3 SCAR=11.0
Pod documented
279 5 my ($self, $size) = @_;
280  
281 5 my $data = $self->get;
282  
283 5 ▶ $size = !$size ? 1 : $size > @$data ? @$data : $size;
Branch: 2 branches
BranchTrueFalseTotal
!$size ? : 1 4 5
$size > @$data ? : 1 3 4
284  
285 5 my $index = $size - 1;
286  
287 5 return [@{$data}[0..$index]];
288 }
289  
290 6553 ▶sub index {
Subroutine index: called CC=1 SCAR=0.0
Pod undocumented
291 6553 my ($self) = @_;
292  
293 6553 my $index = $self->encase('index', {});
294  
295 6553 return $index;
296 }
297  
298 1910 ▶sub index_by_deduced {
Subroutine index_by_deduced: called CC=2 SCAR=6.9
Pod undocumented
299 1910 my ($self) = @_;
300  
301 1910 ▶ my $deduced = $self->index->{deduced} ||= {};
Condition100%2/2
$self->index->{"deduced"} ||= {}
l!l
1759151
MC/DC100%1/1
$self->index->{"deduced"} ||= {}
$self->index->{"deduced"}
Truth table100%2/2
A
A= $self->index->{"deduced"}
Aresult
11
00
302  
303 1910 return $deduced;
304 }
305  
306 1999 ▶sub index_by_digest {
Subroutine index_by_digest: called CC=2 SCAR=6.9
Pod undocumented
307 1999 my ($self) = @_;
308  
309 1999 ▶ my $digest = $self->index->{digest} ||= {};
Condition100%2/2
$self->index->{"digest"} ||= {}
l!l
1848151
MC/DC100%1/1
$self->index->{"digest"} ||= {}
$self->index->{"digest"}
Truth table100%2/2
A
A= $self->index->{"digest"}
Aresult
11
00
310  
311 1999 return $digest;
312 }
313  
314 1466 ▶sub index_by_order {
Subroutine index_by_order: called CC=2 SCAR=6.9
Pod undocumented
315 1466 my ($self) = @_;
316  
317 1466 ▶ my $order = $self->index->{order} ||= {};
Condition100%2/2
$self->index->{"order"} ||= {}
l!l
1315151
MC/DC100%1/1
$self->index->{"order"} ||= {}
$self->index->{"order"}
Truth table100%2/2
A
A= $self->index->{"order"}
Aresult
11
00
318  
319 1466 return $order;
320 }
321  
322 1178 ▶sub index_by_refaddr {
Subroutine index_by_refaddr: called CC=2 SCAR=6.9
Pod undocumented
323 1178 my ($self) = @_;
324  
325 1178 ▶ my $refaddr = $self->index->{refaddr} ||= {};
Condition100%2/2
$self->index->{"refaddr"} ||= {}
l!l
1036142
MC/DC100%1/1
$self->index->{"refaddr"} ||= {}
$self->index->{"refaddr"}
Truth table100%2/2
A
A= $self->index->{"refaddr"}
Aresult
11
00
326  
327 1178 return $refaddr;
328 }
329  
330 1606 ▶sub insert {
Subroutine insert: called CC=3 SCAR=11.0
Pod undocumented
331 1606 my ($self, $value) = @_;
332  
333 1606 my $value_to_deduced = $self->value_to_deduced($value);
334 1606 my $value_to_object = $self->value_to_object($value);
335  
336 1606 my $value_to_digest = $self->value_to_digest($value_to_object);
337 1606 my $index_by_digest = $self->index_by_digest;
338 1606 my $index_by_deduced = $self->index_by_deduced;
339  
340 1606 ▶ if (exists $index_by_digest->{$value_to_digest}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $index_by_digest->{$value_to_digest}) 445 1161 1606
341 445 return $index_by_digest->{$value_to_digest};
342 }
343  
344 1161 my $value_to_refaddr = $self->value_to_refaddr($value_to_object);
345 1161 my $index_by_refaddr = $self->index_by_refaddr;
346  
347 1161 ▶ if (exists $index_by_refaddr->{$value_to_refaddr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $index_by_refaddr->{$value_to_refaddr}) 0 1161 1161
348 0 return $value_to_object;
349 }
350  
351 1161 my $index_by_order = $self->index_by_order;
352 1161 $index_by_order->{int keys %{$index_by_order}} = $value_to_digest;
353  
354 1161 $index_by_digest->{$value_to_digest} = $value_to_object;
355 1161 $index_by_refaddr->{$value_to_refaddr} = $value_to_digest;
356 1161 $index_by_deduced->{$value_to_digest} = $value_to_deduced;
357  
358 1161 return $value_to_object;
359 }
360  
361 2 ▶sub iterator {
Subroutine iterator: called CC=1 SCAR=0.0
Pod documented
362 2 my ($self) = @_;
363  
364 2 my $data = $self->get;
365  
366 2 my $i = 0;
367 2 my $j = 0;
368  
369 20 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
370 20 ▶ return undef if $i > $#{$data};
Branch: 1 branch
BranchTrueFalseTotal
if $i > $#{$data;} 2 18 20
371 18 ▶ return wantarray ? ($j++, $data->[$i++]) : $data->[$i++];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 9 9 18
372 }
373 2 }
374  
375 5 ▶sub intersection {
Subroutine intersection: called CC=9 SCAR=22.1
Pod documented
376 5 my ($self, $data) = @_;
377  
378 5 require Scalar::Util;
379  
380 5 my $set = $self->class->new;
381  
382 5 ▶ if (Scalar::Util::blessed($data) && $data->isa('Venus::Set')) {
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($data) and $data->isa('Venus::Set')) { } 1 4 5
elsif (builtin::blessed($data) and $data->isa('Venus::Array')) { } 1 3 4
elsif (ref $data eq 'ARRAY') { } 3 0 3
Condition100%3/3
builtin::blessed($data) and $data->isa("Venus::Set")
!ll&&!rl&&r
311
MC/DC100%2/2
builtin::blessed($data) and $data->isa("Venus::Set")
builtin::blessed($data) $data->isa("Venus::Set")
Truth table100%3/3
A and B
A= builtin::blessed($data)B= $data->isa("Venus::Set")
ABresult
0X0
100
111
383 1 $set->push($_) for grep $self->contains($_), $data->list;
384 }
385 ▶ elsif (Scalar::Util::blessed($data) && $data->isa('Venus::Array')) {
Condition66%2/3
builtin::blessed($data) and $data->isa("Venus::Array")
!ll&&!rl&&r
301
MC/DC50%1/2
builtin::blessed($data) and $data->isa("Venus::Array")
builtin::blessed($data) $data->isa("Venus::Array")
Truth table66%2/3
A and B
A= builtin::blessed($data)B= $data->isa("Venus::Array")
ABresult
0X0
100
111
386 1 $set->push($_) for grep $self->contains($_), $data->list;
387 }
388 elsif (ref($data) eq 'ARRAY') {
389 3 $set->push($_) for grep $self->contains($_), @$data;
390 }
391  
392 5 return $set;
393 }
394  
395 2 ▶sub intersect {
Subroutine intersect: called CC=2 SCAR=6.9
Pod documented
396 2 my ($self, $data) = @_;
397  
398 2 my $set = $self->intersection($data);
399  
400 2 ▶ return $set->count ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$set->count ? : 1 1 2
401 }
402  
403 2 ▶sub join {
Subroutine join: called CC=2 SCAR=6.9
Pod documented
404 2 my ($self, $delimiter) = @_;
405  
406 2 my $data = $self->get;
407  
408 2 ▶ return CORE::join($delimiter // '', @$data);
Condition100%2/2
$delimiter // ""
l!l
11
MC/DC100%1/1
$delimiter // ""
$delimiter
Truth table100%2/2
A
A= $delimiter
Aresult
11
00
409 }
410  
411 0 ▶sub keyed {
Subroutine keyed: not called CC=1 SCAR=6.9
Pod documented
412 0 my ($self, @keys) = @_;
413  
414 0 my $data = $self->get;
415  
416 0 my $i = 0;
417 0 return {map { $_ => $data->[$i++] } @keys};
418 }
419  
420 1 ▶sub keys {
Subroutine keys: called CC=1 SCAR=0.0
Pod documented
421 1 my ($self) = @_;
422  
423 1 my $data = $self->get;
424  
425 1 return [0..$#{$data}];
426 }
427  
428 2 ▶sub last {
Subroutine last: called CC=1 SCAR=0.0
Pod documented
429 2 my ($self) = @_;
430  
431 2 return $self->value->[-1];
432 }
433  
434 1 ▶sub length {
Subroutine length: called CC=1 SCAR=0.0
Pod documented
435 1 my ($self) = @_;
436  
437 1 return $self->count;
438 }
439  
440 7 ▶sub list {
Subroutine list: called CC=2 SCAR=6.9
Pod documented
441 7 my ($self) = @_;
442  
443 7 ▶ return wantarray ? (@{$self->value}) : scalar(@{$self->value});
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 1 7
444 }
445  
446 3 ▶sub map {
Subroutine map: called CC=4 SCAR=13.9
Pod documented
447 3 my ($self, $code) = @_;
448  
449 3 my $data = $self->get;
450  
451 3 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 3 3
452  
453 3 my $result = [];
454  
455 3 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 27 3 30
456 27 my $index = $i;
457 27 my $value = $data->[$i];
458  
459 27 local $_ = $value;
460 27 CORE::push(@$result, $code->($index, $value));
461 }
462  
463 3 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
464 }
465  
466 2 ▶sub merge {
Subroutine merge: called CC=5 SCAR=20.9
Pod documented
467 2 my ($self, @data) = @_;
468  
469 2 require Scalar::Util;
470  
471 2 for my $data (@data) {
472 6 ▶ if (Scalar::Util::blessed($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($data)) { } 0 6 6
473 0 ▶ $self->push(($data->isa('Venus::Set') || $data->isa('Venus::Array')) ? $data->list : $data);
Branch: 1 branch
BranchTrueFalseTotal
$data->isa('Venus::Set') || $data->isa('Venus::Array') ? : 0 0 0
Condition0%0/3
$data->isa("Venus::Set") or $data->isa("Venus::Array")
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->isa("Venus::Set") or $data->isa("Venus::Array")
$data->isa("Venus::Set") $data->isa("Venus::Array")
Truth table0%0/3
A or B
A= $data->isa("Venus::Set")B= $data->isa("Venus::Array")
ABresult
1X1
011
000
474 }
475 else {
476 6 $self->push($data);
477 }
478 }
479  
480 2 return $self;
481 }
482  
483 2 ▶sub none {
Subroutine none: called CC=6 SCAR=18.3
Pod documented
484 2 my ($self, $code) = @_;
485  
486 2 my $data = $self->get;
487  
488 2 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 2 2
489  
490 2 my $found = 0;
491  
492 2 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 18 2 20
493 18 my $index = $i;
494 18 my $value = $data->[$i];
495  
496 18 local $_ = $value;
497 18 ▶ $found++ if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 0 18 18
498  
499 18 ▶ CORE::last if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 18 18
500 }
501  
502 2 ▶ return $found ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 0 2 2
503 }
504  
505 2207 ▶sub object_to_value {
Subroutine object_to_value: called CC=1 SCAR=0.0
Pod undocumented
506 2207 my ($self, $value) = @_;
507  
508 2207 require Venus::What;
509  
510 2207 return Venus::What->new($value)->detract;
511 }
512  
513 2 ▶sub one {
Subroutine one: called CC=6 SCAR=18.1
Pod documented
514 2 my ($self, $code) = @_;
515  
516 2 my $data = $self->get;
517  
518 2 ▶ $code = sub{} if !$code;
Subroutine __ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 2 2
519  
520 2 my $found = 0;
521  
522 2 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 18 2 20
523 18 my $index = $i;
524 18 my $value = $data->[$i];
525  
526 18 local $_ = $value;
527 18 ▶ $found++ if $code->($index, $value);
Branch: 1 branch
BranchTrueFalseTotal
if &$code($index, $value) 2 16 18
528  
529 18 ▶ CORE::last if $found > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $found > 1 0 18 18
530 }
531  
532 2 ▶ return $found == 1 ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$found == 1 ? : 2 0 2
533 }
534  
535 3 ▶sub order {
Subroutine order: called CC=3 SCAR=11.0
Pod documented
536 3 my ($self, @args) = @_;
537  
538 3 ▶ return $self if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 1 2 3
539  
540 2 my $data = $self->get;
541  
542 2 $self->reset;
543  
544 2 my %seen = ();
545  
546 2 @$data = (map $data->[$_], grep !$seen{$_}++, (@args), 0..$#{$data});
547  
548 2 $self->insert($_) for @$data;
549  
550 2 return $self;
551 }
552  
553 5 ▶sub pairs {
Subroutine pairs: called CC=2 SCAR=7.0
Pod documented
554 5 my ($self) = @_;
555  
556 5 my $data = $self->get;
557  
558 5 my $i = 0;
559 5 my $result = [map +[$i++, $_], @$data];
560  
561 5 ▶ return wantarray ? (@$result) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 5 5
562 }
563  
564 2 ▶sub part {
Subroutine part: called CC=4 SCAR=13.9
Pod documented
565 2 my ($self, $code) = @_;
566  
567 2 my $data = $self->get;
568  
569 2 my $results = [[], []];
570  
571 2 ▶ for (my $i = 0; $i < @$data; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$data) 18 2 20
572 18 my $index = $i;
573 18 my $value = $data->[$i];
574 18 local $_ = $value;
575 18 my $result = $code->($index, $value);
576 18 ▶ my $slot = $result ? $$results[0] : $$results[1];
Branch: 1 branch
BranchTrueFalseTotal
$result ? : 8 10 18
577  
578 18 CORE::push(@$slot, $value);
579 }
580  
581 2 ▶ return wantarray ? (@$results) : $results;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
582 }
583  
584 1 ▶sub pop {
Subroutine pop: called CC=1 SCAR=0.0
Pod documented
585 1 my ($self) = @_;
586  
587 1 return $self->remove($self->last);
588 }
589  
590 168 ▶sub push {
Subroutine push: called CC=2 SCAR=6.9
Pod documented
591 168 my ($self, @args) = @_;
592  
593 168 $self->insert($_) for @args;
594  
595 168 return $self->get;
596 }
597  
598 1 ▶sub random {
Subroutine random: called CC=1 SCAR=0.0
Pod documented
599 1 my ($self) = @_;
600  
601 1 my $data = $self->get;
602  
603 1 return @$data[rand($#{$data}+1)];
604 }
605  
606 19 ▶sub range {
Subroutine range: called CC=2 SCAR=6.9
Pod documented
607 19 my ($self, @args) = @_;
608  
609 19 ▶ return $self->slice(@args) if @args > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @args > 1 1 18 19
610  
611 18 require Venus::Range;
612  
613 18 return scalar Venus::Range->parse(@args, $self->get)->select;
614 }
615  
616 2 ▶sub remove {
Subroutine remove: called CC=4 SCAR=13.9
Pod undocumented
617 2 my ($self, $value) = @_;
618  
619 2 my $value_to_object = $self->value_to_object($value);
620  
621 2 my $value_to_digest = $self->value_to_digest($value_to_object);
622 2 my $index_by_digest = $self->index_by_digest;
623  
624 2 ▶ if (exists $index_by_digest->{$value_to_digest}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $index_by_digest->{$value_to_digest}) 2 0 2
625 2 $value_to_object = delete $index_by_digest->{$value_to_digest};
626 2 $value_to_digest = $self->value_to_digest($value_to_object);
627 }
628  
629 2 my $value_to_refaddr = $self->value_to_refaddr($value_to_object);
630 2 my $index_by_refaddr = $self->index_by_refaddr;
631  
632 2 ▶ if (exists $index_by_refaddr->{$value_to_refaddr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $index_by_refaddr->{$value_to_refaddr}) 2 0 2
633 2 delete $index_by_refaddr->{$value_to_refaddr};
634 }
635  
636 2 my $count = 0;
637 2 my $index_by_order = $self->index_by_order;
638  
639 16 %{$index_by_order} = map {$count++, $index_by_order->{$_}}
640 18 CORE::grep {$index_by_order->{$_} ne $value_to_digest}
641 2 CORE::sort(CORE::keys(%{$index_by_order}));
642  
643 2 my $index_by_deduced = $self->index_by_deduced;
644 2 my $value_to_deduced = delete $index_by_deduced->{$value_to_digest};
645  
646 2 ▶ return $value_to_deduced
Branch: 1 branch
BranchTrueFalseTotal
$value_to_deduced ? : 2 0 2
647 ? $self->object_to_value($value_to_object)
648 : $value_to_object;
649 }
650  
651 7 ▶sub reset {
Subroutine reset: called CC=2 SCAR=6.9
Pod undocumented
652 7 my ($self, @data) = @_;
653  
654 7 $self->uncase('index');
655  
656 7 $self->insert($_) for @data;
657  
658 7 return $self;
659 }
660  
661 1 ▶sub reverse {
Subroutine reverse: called CC=2 SCAR=6.9
Pod documented
662 1 my ($self) = @_;
663  
664 1 my $data = $self->get;
665  
666 1 $self->reset;
667  
668 1 $self->insert($_) for CORE::reverse(@$data);
669  
670 1 return $self->get;
671 }
672  
673 1 ▶sub rotate {
Subroutine rotate: called CC=2 SCAR=6.9
Pod documented
674 1 my ($self) = @_;
675  
676 1 my $data = $self->get;
677  
678 1 $self->reset;
679  
680 1 CORE::push(@$data, CORE::shift(@$data));
681  
682 1 $self->insert($_) for @$data;
683  
684 1 return $self->get;
685 }
686  
687 1 ▶sub rsort {
Subroutine rsort: called CC=1 SCAR=0.0
Pod documented
688 1 my ($self) = @_;
689  
690 1 my $data = $self->get;
691  
692 1 return [CORE::sort { $b cmp $a } @$data];
693 }
694  
695 2 ▶sub set {
Subroutine set: called CC=2 SCAR=7.1
Pod documented
696 2 my ($self, @args) = @_;
697  
698 2 ▶ return $self->value if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 2 2
699  
700 2 return $self->insert(@args);
701 }
702  
703 1 ▶sub shift {
Subroutine shift: called CC=2 SCAR=6.9
Pod documented
704 1 my ($self) = @_;
705  
706 1 my $data = $self->get;
707  
708 1 $self->reset;
709  
710 1 my $result = CORE::shift(@$data);
711  
712 1 $self->insert($_) for @$data;
713  
714 1 return $result;
715 }
716  
717 1 ▶sub shuffle {
Subroutine shuffle: called CC=2 SCAR=6.9
Pod documented
718 1 my ($self) = @_;
719  
720 1 my $data = $self->get;
721 1 my $result = [@$data];
722  
723 1 for my $index (0..$#$result) {
724 9 my $other = int(rand(@$result));
725 9 my $stash = $result->[$index];
726 9 $result->[$index] = $result->[$other];
727 9 $result->[$other] = $stash;
728 }
729  
730 1 return $result;
731 }
732  
733 2 ▶sub slice {
Subroutine slice: called CC=1 SCAR=0.0
Pod documented
734 2 my ($self, @args) = @_;
735  
736 2 my $data = $self->get;
737  
738 2 return [@$data[@args]];
739 }
740  
741 1 ▶sub sort {
Subroutine sort: called CC=1 SCAR=0.0
Pod documented
742 1 my ($self) = @_;
743  
744 1 my $data = $self->get;
745  
746 1 return [CORE::sort { $a cmp $b } @$data];
747 }
748  
749 3 ▶sub subset {
Subroutine subset: called CC=12 SCAR=34.6
Pod documented
750 3 my ($self, $data) = @_;
751  
752 3 require Scalar::Util;
753  
754 3 my $set = $self->class->new;
755  
756 3 ▶ if (Scalar::Util::blessed($data) && $data->isa('Venus::Set')) {
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($data) and $data->isa('Venus::Set')) { } 0 3 3
elsif (builtin::blessed($data) and $data->isa('Venus::Array')) { } 0 3 3
elsif (ref $data eq 'ARRAY') { } 3 0 3
Condition33%1/3
builtin::blessed($data) and $data->isa("Venus::Set")
!ll&&!rl&&r
300
MC/DC0%0/2
builtin::blessed($data) and $data->isa("Venus::Set")
builtin::blessed($data) $data->isa("Venus::Set")
Truth table33%1/3
A and B
A= builtin::blessed($data)B= $data->isa("Venus::Set")
ABresult
0X0
100
111
757 0 $set->push($_) for grep $self->contains($_), $data->list;
758 0 ▶ return true if $data->count == $set->count;
Branch: 1 branch
BranchTrueFalseTotal
if $data->count == $set->count 0 0 0
759 }
760 ▶ elsif (Scalar::Util::blessed($data) && $data->isa('Venus::Array')) {
Condition33%1/3
builtin::blessed($data) and $data->isa("Venus::Array")
!ll&&!rl&&r
300
MC/DC0%0/2
builtin::blessed($data) and $data->isa("Venus::Array")
builtin::blessed($data) $data->isa("Venus::Array")
Truth table33%1/3
A and B
A= builtin::blessed($data)B= $data->isa("Venus::Array")
ABresult
0X0
100
111
761 0 $set->push($_) for grep $self->contains($_), $data->list;
762 0 ▶ return true if $data->count == $set->count;
Branch: 1 branch
BranchTrueFalseTotal
if $data->count == $set->count 0 0 0
763 }
764 elsif (ref($data) eq 'ARRAY') {
765 3 $set->push($_) for grep $self->contains($_), @$data;
766 3 ▶ return true if @$data == $set->count;
Branch: 1 branch
BranchTrueFalseTotal
if @$data == $set->count 2 1 3
767 }
768  
769 1 return false;
770 }
771  
772 3 ▶sub superset {
Subroutine superset: called CC=15 SCAR=40.6
Pod documented
773 3 my ($self, $data) = @_;
774  
775 3 require Scalar::Util;
776  
777 3 my $set = $self->class->new;
778  
779 3 ▶ if (Scalar::Util::blessed($data) && $data->isa('Venus::Set')) {
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($data) and $data->isa('Venus::Set')) { } 0 3 3
elsif (builtin::blessed($data) and $data->isa('Venus::Array')) { } 0 3 3
elsif (ref $data eq 'ARRAY') { } 3 0 3
Condition33%1/3
builtin::blessed($data) and $data->isa("Venus::Set")
!ll&&!rl&&r
300
MC/DC0%0/2
builtin::blessed($data) and $data->isa("Venus::Set")
builtin::blessed($data) $data->isa("Venus::Set")
Truth table33%1/3
A and B
A= builtin::blessed($data)B= $data->isa("Venus::Set")
ABresult
0X0
100
111
780 0 $set->push($_) for grep !$data->contains($_), $self->list;
781 0 ▶ return false if $set->count || $data->count <= $self->count;;
Branch: 1 branch
BranchTrueFalseTotal
if $set->count or $data->count <= $self->count 0 0 0
Condition0%0/3
$set->count or $data->count <= $self->count
l!l&&r!l&&!r
000
MC/DC0%0/2
$set->count or $data->count <= $self->count
$set->count $data->count <= $self->count
Truth table0%0/3
A or B
A= $set->countB= $data->count <= $self->count
ABresult
1X1
011
000
782 }
783 ▶ elsif (Scalar::Util::blessed($data) && $data->isa('Venus::Array')) {
Condition33%1/3
builtin::blessed($data) and $data->isa("Venus::Array")
!ll&&!rl&&r
300
MC/DC0%0/2
builtin::blessed($data) and $data->isa("Venus::Array")
builtin::blessed($data) $data->isa("Venus::Array")
Truth table33%1/3
A and B
A= builtin::blessed($data)B= $data->isa("Venus::Array")
ABresult
0X0
100
111
784 0 my $temp = $self->class->new($data->get);
785 0 $set->push($_) for grep !$temp->contains($_), $self->list;
786 0 ▶ return false if $set->count || $temp->count <= $self->count;
Branch: 1 branch
BranchTrueFalseTotal
if $set->count or $temp->count <= $self->count 0 0 0
Condition0%0/3
$set->count or $temp->count <= $self->count
l!l&&r!l&&!r
000
MC/DC0%0/2
$set->count or $temp->count <= $self->count
$set->count $temp->count <= $self->count
Truth table0%0/3
A or B
A= $set->countB= $temp->count <= $self->count
ABresult
1X1
011
000
787 }
788 elsif (ref($data) eq 'ARRAY') {
789 3 my $temp = $self->class->new($data);
790 3 $set->push($_) for grep !$temp->contains($_), $self->list;
791 3 ▶ return false if $set->count || $temp->count <= $self->count;
Branch: 1 branch
BranchTrueFalseTotal
if $set->count or $temp->count <= $self->count 1 2 3
Condition66%2/3
$set->count or $temp->count <= $self->count
l!l&&r!l&&!r
012
MC/DC50%1/2
$set->count or $temp->count <= $self->count
$set->count $temp->count <= $self->count
Truth table66%2/3
A or B
A= $set->countB= $temp->count <= $self->count
ABresult
1X1
011
000
792 }
793  
794 2 return true;
795 }
796  
797 5 ▶sub tail {
Subroutine tail: called CC=3 SCAR=11.0
Pod documented
798 5 my ($self, $size) = @_;
799  
800 5 my $data = $self->get;
801  
802 5 ▶ $size = !$size ? 1 : $size > @$data ? @$data : $size;
Branch: 2 branches
BranchTrueFalseTotal
!$size ? : 1 4 5
$size > @$data ? : 1 3 4
803  
804 5 my $index = $#$data - ($size - 1);
805  
806 5 return [@{$data}[$index..$#$data]];
807 }
808  
809 1 ▶sub unique {
Subroutine unique: called CC=1 SCAR=0.0
Pod documented
810 1 my ($self) = @_;
811  
812 1 my $data = $self->get;
813  
814 1 return $data;
815 }
816  
817 1 ▶sub unshift {
Subroutine unshift: called CC=2 SCAR=6.9
Pod documented
818 1 my ($self, @args) = @_;
819  
820 1 my $data = $self->get;
821  
822 1 $self->reset;
823  
824 1 CORE::unshift(@$data, @args);
825  
826 1 $self->insert($_) for @$data;
827  
828 1 return $data;
829 }
830  
831 302 ▶sub value {
Subroutine value: called CC=3 SCAR=11.0
Pod undocumented
832 302 my ($self) = @_;
833  
834 302 my $results = [];
835  
836 302 my $index_by_deduced = $self->index_by_deduced;
837 302 my $index_by_digest = $self->index_by_digest;
838 302 my $index_by_order = $self->index_by_order;
839  
840 302 for my $index (CORE::sort(CORE::keys(%{$index_by_order}))) {
841 2205 my $digest = $index_by_order->{$index};
842 2205 my $deduced = $index_by_deduced->{$digest};
843 2205 my $value = $index_by_digest->{$index_by_order->{$index}};
844 2205 ▶ CORE::push(@{$results}, $deduced ? $self->object_to_value($value) : $value);
Branch: 1 branch
BranchTrueFalseTotal
$deduced ? : 2205 0 2205
845 }
846  
847 302 return $results;
848 }
849  
850 1606 ▶sub value_to_deduced {
Subroutine value_to_deduced: called CC=2 SCAR=7.1
Pod undocumented
851 1606 my ($self, $value) = @_;
852  
853 1606 require Scalar::Util;
854  
855 1606 ▶ return Scalar::Util::blessed($value) ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($value) ? : 0 1606 1606
856 }
857  
858 1698 ▶sub value_to_digest {
Subroutine value_to_digest: called CC=1 SCAR=0.0
Pod undocumented
859 1698 my ($self, $value) = @_;
860  
861 1698 require Digest;
862  
863 1698 my $digest = Digest->new('SHA-1');
864 1698 my $method = "Venus::Role::Dumpable::dump";
865  
866 1698 return $digest->add($value->$method)->hexdigest;
867 }
868  
869 1696 ▶sub value_to_object {
Subroutine value_to_object: called CC=1 SCAR=0.0
Pod undocumented
870 1696 my ($self, $value) = @_;
871  
872 1696 require Venus::What;
873  
874 1696 return Venus::What->new($value)->deduce;
875 }
876  
877 1178 ▶sub value_to_refaddr {
Subroutine value_to_refaddr: called CC=1 SCAR=0.0
Pod undocumented
878 1178 my ($self, $value) = @_;
879  
880 1178 require Scalar::Util;
881  
882 1178 return Scalar::Util::refaddr($value);
883 }
884  
885 3 1;
886  
887  
888  
889 =head1 NAME
890  
891 Venus::Set - Set Class
892  
893 =cut
894  
895 =head1 ABSTRACT
896  
897 Set Class for Perl 5
898  
899 =cut
900  
901 =head1 SYNOPSIS
902  
903 package main;
904  
905 use Venus::Set;
906  
907 my $set = Venus::Set->new([1,1,2,2,3,3,4,4,5..9]);
908  
909 # $set->count;
910  
911 # 4
912  
913 =cut
914  
915 =head1 DESCRIPTION
916  
917 This package provides a representation of a collection of ordered unique values
918 and methods for validating and manipulating it.
919  
920 =cut
921  
922 =head1 ATTRIBUTES
923  
924 This package has the following attributes:
925  
926 =cut
927  
928 =head2 accept
929  
930 accept(string $data) (string)
931  
932 The accept attribute is read-write, accepts C<(string)> values, and is
933 optional.
934  
935 I<Since C<4.11>>
936  
937 =over 4
938  
939 =item accept example 1
940  
941 # given: synopsis
942  
943 package main;
944  
945 my $set_accept = $set->accept("number");
946  
947 # "number"
948  
949 =back
950  
951 =over 4
952  
953 =item accept example 2
954  
955 # given: synopsis
956  
957 # given: example-1 accept
958  
959 package main;
960  
961 my $get_accept = $set->accept;
962  
963 # "number"
964  
965 =back
966  
967 =cut
968  
969 =head1 INHERITS
970  
971 This package inherits behaviors from:
972  
973 L<Venus::Kind::Utility>
974  
975 =cut
976  
977 =head1 INTEGRATES
978  
979 This package integrates behaviors from:
980  
981 L<Venus::Role::Mappable>
982  
983 L<Venus::Role::Encaseable>
984  
985 =cut
986  
987 =head1 METHODS
988  
989 This package provides the following methods:
990  
991 =cut
992  
993 =head2 all
994  
995 all(coderef $code) (boolean)
996  
997 The all method returns true if the callback returns true for all of the
998 elements.
999  
1000 I<Since C<4.11>>
1001  
1002 =over 4
1003  
1004 =item all example 1
1005  
1006 # given: synopsis;
1007  
1008 my $all = $set->all(sub {
1009 $_ > 0;
1010 });
1011  
1012 # 1
1013  
1014 =back
1015  
1016 =over 4
1017  
1018 =item all example 2
1019  
1020 # given: synopsis;
1021  
1022 my $all = $set->all(sub {
1023 my ($key, $value) = @_;
1024  
1025 $value > 0;
1026 });
1027  
1028 # 1
1029  
1030 =back
1031  
1032 =cut
1033  
1034 =head2 any
1035  
1036 any(coderef $code) (boolean)
1037  
1038 The any method returns true if the callback returns true for any of the
1039 elements.
1040  
1041 I<Since C<4.11>>
1042  
1043 =over 4
1044  
1045 =item any example 1
1046  
1047 # given: synopsis;
1048  
1049 my $any = $set->any(sub {
1050 $_ > 4;
1051 });
1052  
1053 =back
1054  
1055 =over 4
1056  
1057 =item any example 2
1058  
1059 # given: synopsis;
1060  
1061 my $any = $set->any(sub {
1062 my ($key, $value) = @_;
1063  
1064 $value > 4;
1065 });
1066  
1067 =back
1068  
1069 =cut
1070  
1071 =head2 attest
1072  
1073 attest() (any)
1074  
1075 The attest method validates the values using the L<Venus::Assert> expression in
1076 the L</accept> attribute and returns the result.
1077  
1078 I<Since C<4.11>>
1079  
1080 =over 4
1081  
1082 =item attest example 1
1083  
1084 # given: synopsis
1085  
1086 package main;
1087  
1088 my $attest = $set->attest;
1089  
1090 # [1..9]
1091  
1092 =back
1093  
1094 =over 4
1095  
1096 =item attest example 2
1097  
1098 # given: synopsis
1099  
1100 package main;
1101  
1102 $set->accept('number | object');
1103  
1104 my $attest = $set->attest;
1105  
1106 # [1..9]
1107  
1108 =back
1109  
1110 =over 4
1111  
1112 =item attest example 3
1113  
1114 # given: synopsis
1115  
1116 package main;
1117  
1118 $set->accept('string');
1119  
1120 my $attest = $set->attest;
1121  
1122 # Exception! (isa Venus::Check::Error)
1123  
1124 =back
1125  
1126 =over 4
1127  
1128 =item attest example 4
1129  
1130 # given: synopsis
1131  
1132 package main;
1133  
1134 $set->accept('number');
1135  
1136 my $attest = $set->attest;
1137  
1138 # [1..9]
1139  
1140 =back
1141  
1142 =cut
1143  
1144 =head2 call
1145  
1146 call(string $iterable, string $method) (any)
1147  
1148 The call method executes the given method (named using the first argument)
1149 which performs an iteration (i.e. takes a callback) and calls the method (named
1150 using the second argument) on the object (or value) and returns the result of
1151 the iterable method.
1152  
1153 I<Since C<4.11>>
1154  
1155 =over 4
1156  
1157 =item call example 1
1158  
1159 # given: synopsis
1160  
1161 package main;
1162  
1163 my $call = $set->call('map', 'incr');
1164  
1165 # [2..10]
1166  
1167 =back
1168  
1169 =over 4
1170  
1171 =item call example 2
1172  
1173 # given: synopsis
1174  
1175 package main;
1176  
1177 my $call = $set->call('grep', 'gt', 4);
1178  
1179 # [4..9]
1180  
1181 =back
1182  
1183 =cut
1184  
1185 =head2 contains
1186  
1187 contains(any $value) (boolean)
1188  
1189 The contains method returns true if the value provided already exists in the
1190 set, otherwise it returns false.
1191  
1192 I<Since C<4.11>>
1193  
1194 =over 4
1195  
1196 =item contains example 1
1197  
1198 # given: synopsis;
1199  
1200 my $contains = $set->contains(1);
1201  
1202 # true
1203  
1204 =back
1205  
1206 =over 4
1207  
1208 =item contains example 2
1209  
1210 # given: synopsis;
1211  
1212 my $contains = $set->contains(0);
1213  
1214 # false
1215  
1216 =back
1217  
1218 =cut
1219  
1220 =head2 count
1221  
1222 count() (number)
1223  
1224 The count method returns the number of elements within the set.
1225  
1226 I<Since C<4.11>>
1227  
1228 =over 4
1229  
1230 =item count example 1
1231  
1232 # given: synopsis;
1233  
1234 my $count = $set->count;
1235  
1236 # 9
1237  
1238 =back
1239  
1240 =cut
1241  
1242 =head2 default
1243  
1244 default() (arrayref)
1245  
1246 The default method returns the default value, i.e. C<[]>.
1247  
1248 I<Since C<4.11>>
1249  
1250 =over 4
1251  
1252 =item default example 1
1253  
1254 # given: synopsis;
1255  
1256 my $default = $set->default;
1257  
1258 # []
1259  
1260 =back
1261  
1262 =cut
1263  
1264 =head2 delete
1265  
1266 delete(number $index) (any)
1267  
1268 The delete method returns the value of the element at the index specified after
1269 removing it from the set.
1270  
1271 I<Since C<4.11>>
1272  
1273 =over 4
1274  
1275 =item delete example 1
1276  
1277 # given: synopsis;
1278  
1279 my $delete = $set->delete(2);
1280  
1281 # 3
1282  
1283 =back
1284  
1285 =cut
1286  
1287 =head2 difference
1288  
1289 difference(arrayref | Venus::Array | Venus::Set $data) (Venus::Set)
1290  
1291 The difference method returns a new set containing only the values that don't
1292 exist in the source.
1293  
1294 I<Since C<4.11>>
1295  
1296 =over 4
1297  
1298 =item difference example 1
1299  
1300 # given: synopsis
1301  
1302 package main;
1303  
1304 my $difference = $set->difference([9, 10, 11]);
1305  
1306 # bless(..., "Venus::Set")
1307  
1308 # $difference->list;
1309  
1310 # [10, 11]
1311  
1312 =back
1313  
1314 =over 4
1315  
1316 =item difference example 2
1317  
1318 # given: synopsis
1319  
1320 package main;
1321  
1322 my $difference = $set->difference(Venus::Set->new([9, 10, 11]));
1323  
1324 # bless(..., "Venus::Set")
1325  
1326 # $difference->list;
1327  
1328 # [10, 11]
1329  
1330 =back
1331  
1332 =over 4
1333  
1334 =item difference example 3
1335  
1336 # given: synopsis
1337  
1338 package main;
1339  
1340 use Venus::Array;
1341  
1342 my $difference = $set->difference(Venus::Array->new([9, 10, 11]));
1343  
1344 # bless(..., "Venus::Set")
1345  
1346 # $difference->list;
1347  
1348 # [10, 11]
1349  
1350 =back
1351  
1352 =cut
1353  
1354 =head2 different
1355  
1356 different(arrayref | Venus::Array | Venus::Set $data) (boolean)
1357  
1358 The different method returns true if the values provided don't exist in the
1359 source.
1360  
1361 I<Since C<4.11>>
1362  
1363 =over 4
1364  
1365 =item different example 1
1366  
1367 # given: synopsis
1368  
1369 package main;
1370  
1371 my $different = $set->different([1..10]);
1372  
1373 # true
1374  
1375 =back
1376  
1377 =over 4
1378  
1379 =item different example 2
1380  
1381 # given: synopsis
1382  
1383 package main;
1384  
1385 my $different = $set->different([1..9]);
1386  
1387 # false
1388  
1389 =back
1390  
1391 =cut
1392  
1393 =head2 each
1394  
1395 each(coderef $code) (arrayref)
1396  
1397 The each method executes a callback for each element in the set passing the
1398 index and value as arguments. This method can return a list of values in
1399 list-context.
1400  
1401 I<Since C<4.11>>
1402  
1403 =over 4
1404  
1405 =item each example 1
1406  
1407 # given: synopsis;
1408  
1409 my $each = $set->each(sub {
1410 [$_]
1411 });
1412  
1413 # [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
1414  
1415 =back
1416  
1417 =over 4
1418  
1419 =item each example 2
1420  
1421 # given: synopsis;
1422  
1423 my $each = $set->each(sub {
1424 my ($key, $value) = @_;
1425  
1426 [$key, $value]
1427 });
1428  
1429 # [
1430 # [0, 1],
1431 # [1, 2],
1432 # [2, 3],
1433 # [3, 4],
1434 # [4, 5],
1435 # [5, 6],
1436 # [6, 7],
1437 # [7, 8],
1438 # [8, 9],
1439 # ]
1440  
1441 =back
1442  
1443 =cut
1444  
1445 =head2 empty
1446  
1447 empty() (Venus::Array)
1448  
1449 The empty method drops all elements from the set.
1450  
1451 I<Since C<4.11>>
1452  
1453 =over 4
1454  
1455 =item empty example 1
1456  
1457 # given: synopsis;
1458  
1459 my $empty = $set->empty;
1460  
1461 # bless({}, "Venus::Set")
1462  
1463 =back
1464  
1465 =cut
1466  
1467 =head2 exists
1468  
1469 exists(number $index) (boolean)
1470  
1471 The exists method returns true if the element at the index specified exists,
1472 otherwise it returns false.
1473  
1474 I<Since C<4.11>>
1475  
1476 =over 4
1477  
1478 =item exists example 1
1479  
1480 # given: synopsis;
1481  
1482 my $exists = $set->exists(0);
1483  
1484 # true
1485  
1486 =back
1487  
1488 =cut
1489  
1490 =head2 first
1491  
1492 first() (any)
1493  
1494 The first method returns the value of the first element.
1495  
1496 I<Since C<4.11>>
1497  
1498 =over 4
1499  
1500 =item first example 1
1501  
1502 # given: synopsis;
1503  
1504 my $first = $set->first;
1505  
1506 # 1
1507  
1508 =back
1509  
1510 =cut
1511  
1512 =head2 get
1513  
1514 get(number $index) (any)
1515  
1516 The get method returns the value at the position specified.
1517  
1518 I<Since C<4.11>>
1519  
1520 =over 4
1521  
1522 =item get example 1
1523  
1524 # given: synopsis
1525  
1526 package main;
1527  
1528 my $get = $set->get(0);
1529  
1530 # 1
1531  
1532 =back
1533  
1534 =over 4
1535  
1536 =item get example 2
1537  
1538 # given: synopsis
1539  
1540 package main;
1541  
1542 my $get = $set->get(3);
1543  
1544 # 4
1545  
1546 =back
1547  
1548 =cut
1549  
1550 =head2 grep
1551  
1552 grep(coderef $code) (arrayref)
1553  
1554 The grep method executes a callback for each element in the array passing the
1555 value as an argument, returning a new array reference containing the elements
1556 for which the returned true. This method can return a list of values in
1557 list-context.
1558  
1559 I<Since C<4.11>>
1560  
1561 =over 4
1562  
1563 =item grep example 1
1564  
1565 # given: synopsis;
1566  
1567 my $grep = $set->grep(sub {
1568 $_ > 3
1569 });
1570  
1571 # [4..9]
1572  
1573 =back
1574  
1575 =over 4
1576  
1577 =item grep example 2
1578  
1579 # given: synopsis;
1580  
1581 my $grep = $set->grep(sub {
1582 my ($key, $value) = @_;
1583  
1584 $value > 3
1585 });
1586  
1587 # [4..9]
1588  
1589 =back
1590  
1591 =cut
1592  
1593 =head2 head
1594  
1595 head(number $size) (arrayref)
1596  
1597 The head method returns the topmost elements, limited by the desired size
1598 specified.
1599  
1600 I<Since C<4.11>>
1601  
1602 =over 4
1603  
1604 =item head example 1
1605  
1606 # given: synopsis;
1607  
1608 my $head = $set->head;
1609  
1610 # [1]
1611  
1612 =back
1613  
1614 =over 4
1615  
1616 =item head example 2
1617  
1618 # given: synopsis;
1619  
1620 my $head = $set->head(1);
1621  
1622 # [1]
1623  
1624 =back
1625  
1626 =over 4
1627  
1628 =item head example 3
1629  
1630 # given: synopsis;
1631  
1632 my $head = $set->head(2);
1633  
1634 # [1,2]
1635  
1636 =back
1637  
1638 =over 4
1639  
1640 =item head example 4
1641  
1642 # given: synopsis;
1643  
1644 my $head = $set->head(5);
1645  
1646 # [1..5]
1647  
1648 =back
1649  
1650 =over 4
1651  
1652 =item head example 5
1653  
1654 # given: synopsis;
1655  
1656 my $head = $set->head(20);
1657  
1658 # [1..9]
1659  
1660 =back
1661  
1662 =cut
1663  
1664 =head2 intersect
1665  
1666 intersect(arrayref | Venus::Array | Venus::Set $data) (boolean)
1667  
1668 The intersect method returns true if the values provided already exist in the
1669 source.
1670  
1671 I<Since C<4.11>>
1672  
1673 =over 4
1674  
1675 =item intersect example 1
1676  
1677 # given: synopsis
1678  
1679 package main;
1680  
1681 my $intersect = $set->intersect([9, 10]);
1682  
1683 # true
1684  
1685 =back
1686  
1687 =over 4
1688  
1689 =item intersect example 2
1690  
1691 # given: synopsis
1692  
1693 package main;
1694  
1695 my $intersect = $set->intersect([10, 11]);
1696  
1697 # false
1698  
1699 =back
1700  
1701 =cut
1702  
1703 =head2 intersection
1704  
1705 intersection(arrayref | Venus::Array | Venus::Set $data) (Venus::Set)
1706  
1707 The intersection method returns a new set containing only the values that
1708 already exist in the source.
1709  
1710 I<Since C<4.11>>
1711  
1712 =over 4
1713  
1714 =item intersection example 1
1715  
1716 # given: synopsis
1717  
1718 package main;
1719  
1720 $set->push(10);
1721  
1722 my $intersection = $set->intersection([9, 10, 11]);
1723  
1724 # bless(..., "Venus::Set")
1725  
1726 # $intersection->list;
1727  
1728 # [9, 10]
1729  
1730 =back
1731  
1732 =over 4
1733  
1734 =item intersection example 2
1735  
1736 # given: synopsis
1737  
1738 package main;
1739  
1740 $set->push(10);
1741  
1742 my $intersection = $set->intersection(Venus::Set->new([9, 10, 11]));
1743  
1744 # bless(..., "Venus::Set")
1745  
1746 # $intersection->list;
1747  
1748 # [9, 10]
1749  
1750 =back
1751  
1752 =over 4
1753  
1754 =item intersection example 3
1755  
1756 # given: synopsis
1757  
1758 package main;
1759  
1760 use Venus::Array;
1761  
1762 $set->push(10);
1763  
1764 my $intersection = $set->intersection(Venus::Array->new([9, 10, 11]));
1765  
1766 # bless(..., "Venus::Set")
1767  
1768 # $intersection->list;
1769  
1770 # [9, 10]
1771  
1772 =back
1773  
1774 =cut
1775  
1776 =head2 iterator
1777  
1778 iterator() (coderef)
1779  
1780 The iterator method returns a code reference which can be used to iterate over
1781 the array. Each time the iterator is executed it will return the next element
1782 in the array until all elements have been seen, at which point the iterator
1783 will return an undefined value. This method can return a tuple with the key and
1784 value in list-context.
1785  
1786 I<Since C<4.11>>
1787  
1788 =over 4
1789  
1790 =item iterator example 1
1791  
1792 # given: synopsis;
1793  
1794 my $iterator = $set->iterator;
1795  
1796 # sub { ... }
1797  
1798 # while (my $value = $iterator->()) {
1799 # say $value; # 1
1800 # }
1801  
1802 =back
1803  
1804 =over 4
1805  
1806 =item iterator example 2
1807  
1808 # given: synopsis;
1809  
1810 my $iterator = $set->iterator;
1811  
1812 # sub { ... }
1813  
1814 # while (grep defined, my ($key, $value) = $iterator->()) {
1815 # say $value; # 1
1816 # }
1817  
1818 =back
1819  
1820 =cut
1821  
1822 =head2 join
1823  
1824 join(string $seperator) (string)
1825  
1826 The join method returns a string consisting of all the elements in the array
1827 joined by the join-string specified by the argument. Note: If the argument is
1828 omitted, an empty string will be used as the join-string.
1829  
1830 I<Since C<4.11>>
1831  
1832 =over 4
1833  
1834 =item join example 1
1835  
1836 # given: synopsis;
1837  
1838 my $join = $set->join;
1839  
1840 # 123456789
1841  
1842 =back
1843  
1844 =over 4
1845  
1846 =item join example 2
1847  
1848 # given: synopsis;
1849  
1850 my $join = $set->join(', ');
1851  
1852 # "1, 2, 3, 4, 5, 6, 7, 8, 9"
1853  
1854 =back
1855  
1856 =cut
1857  
1858 =head2 keyed
1859  
1860 keyed(string @keys) (hashref)
1861  
1862 The keyed method returns a hash reference where the arguments become the keys,
1863 and the elements of the array become the values.
1864  
1865 I<Since C<4.11>>
1866  
1867 =over 4
1868  
1869 =item keyed example 1
1870  
1871 package main;
1872  
1873 use Venus::Array;
1874  
1875 my $set = Venus::Array->new([1..4]);
1876  
1877 my $keyed = $set->keyed('a'..'d');
1878  
1879 # { a => 1, b => 2, c => 3, d => 4 }
1880  
1881 =back
1882  
1883 =cut
1884  
1885 =head2 keys
1886  
1887 keys() (arrayref)
1888  
1889 The keys method returns an array reference consisting of the indicies of the
1890 array.
1891  
1892 I<Since C<4.11>>
1893  
1894 =over 4
1895  
1896 =item keys example 1
1897  
1898 # given: synopsis;
1899  
1900 my $keys = $set->keys;
1901  
1902 # [0..8]
1903  
1904 =back
1905  
1906 =cut
1907  
1908 =head2 last
1909  
1910 last() (any)
1911  
1912 The last method returns the value of the last element in the array.
1913  
1914 I<Since C<4.11>>
1915  
1916 =over 4
1917  
1918 =item last example 1
1919  
1920 # given: synopsis;
1921  
1922 my $last = $set->last;
1923  
1924 # 9
1925  
1926 =back
1927  
1928 =cut
1929  
1930 =head2 length
1931  
1932 length() (number)
1933  
1934 The length method returns the number of elements within the array, and is an
1935 alias for the L</count> method.
1936  
1937 I<Since C<4.11>>
1938  
1939 =over 4
1940  
1941 =item length example 1
1942  
1943 # given: synopsis;
1944  
1945 my $length = $set->length;
1946  
1947 # 9
1948  
1949 =back
1950  
1951 =cut
1952  
1953 =head2 list
1954  
1955 list() (any)
1956  
1957 The list method returns a shallow copy of the underlying array reference as an
1958 array reference.
1959  
1960 I<Since C<4.11>>
1961  
1962 =over 4
1963  
1964 =item list example 1
1965  
1966 # given: synopsis;
1967  
1968 my $list = $set->list;
1969  
1970 # 9
1971  
1972 =back
1973  
1974 =over 4
1975  
1976 =item list example 2
1977  
1978 # given: synopsis;
1979  
1980 my @list = $set->list;
1981  
1982 # (1..9)
1983  
1984 =back
1985  
1986 =cut
1987  
1988 =head2 map
1989  
1990 map(coderef $code) (arrayref)
1991  
1992 The map method iterates over each element in the array, executing the code
1993 reference supplied in the argument, passing the routine the value at the
1994 current position in the loop and returning a new array reference containing the
1995 elements for which the argument returns a value or non-empty list. This method
1996 can return a list of values in list-context.
1997  
1998 I<Since C<4.11>>
1999  
2000 =over 4
2001  
2002 =item map example 1
2003  
2004 # given: synopsis;
2005  
2006 my $map = $set->map(sub {
2007 $_ * 2
2008 });
2009  
2010 # [2, 4, 6, 8, 10, 12, 14, 16, 18]
2011  
2012 =back
2013  
2014 =over 4
2015  
2016 =item map example 2
2017  
2018 # given: synopsis;
2019  
2020 my $map = $set->map(sub {
2021 my ($key, $value) = @_;
2022  
2023 [$key, ($value * 2)]
2024 });
2025  
2026 # [
2027 # [0, 2],
2028 # [1, 4],
2029 # [2, 6],
2030 # [3, 8],
2031 # [4, 10],
2032 # [5, 12],
2033 # [6, 14],
2034 # [7, 16],
2035 # [8, 18],
2036 # ]
2037  
2038 =back
2039  
2040 =cut
2041  
2042 =head2 merge
2043  
2044 merge(any @data) (Venus::Set)
2045  
2046 The merge method merges the arguments provided with the existing set.
2047  
2048 I<Since C<4.11>>
2049  
2050 =over 4
2051  
2052 =item merge example 1
2053  
2054 # given: synopsis;
2055  
2056 my $merge = $set->merge(6..9);
2057  
2058 # bless(..., "Venus::Set")
2059  
2060 # $set->list;
2061  
2062 # [1..9]
2063  
2064 =back
2065  
2066 =over 4
2067  
2068 =item merge example 2
2069  
2070 # given: synopsis;
2071  
2072 my $merge = $set->merge(8, 10);
2073  
2074 # bless(..., "Venus::Set")
2075  
2076 # $set->list;
2077  
2078 # [1..10]
2079  
2080 =back
2081  
2082 =cut
2083  
2084 =head2 new
2085  
2086 new(any @args) (Venus::Set)
2087  
2088 The new method constructs an instance of the package.
2089  
2090 I<Since C<4.15>>
2091  
2092 =over 4
2093  
2094 =item new example 1
2095  
2096 package main;
2097  
2098 use Venus::Set;
2099  
2100 my $new = Venus::Set->new;
2101  
2102 # bless(..., "Venus::Set")
2103  
2104 =back
2105  
2106 =over 4
2107  
2108 =item new example 2
2109  
2110 package main;
2111  
2112 use Venus::Set;
2113  
2114 my $new = Venus::Set->new([1,1,2,2,3,3,4,4,5..9]);
2115  
2116 # bless(..., "Venus::Set")
2117  
2118 =back
2119  
2120 =over 4
2121  
2122 =item new example 3
2123  
2124 package main;
2125  
2126 use Venus::Set;
2127  
2128 my $new = Venus::Set->new(value => [1,1,2,2,3,3,4,4,5..9]);
2129  
2130 # bless(..., "Venus::Set")
2131  
2132 =back
2133  
2134 =cut
2135  
2136 =head2 none
2137  
2138 none(coderef $code) (boolean)
2139  
2140 The none method returns true if none of the elements in the array meet the
2141 criteria set by the operand and rvalue.
2142  
2143 I<Since C<4.11>>
2144  
2145 =over 4
2146  
2147 =item none example 1
2148  
2149 # given: synopsis;
2150  
2151 my $none = $set->none(sub {
2152 $_ < 1
2153 });
2154  
2155 # 1
2156  
2157 =back
2158  
2159 =over 4
2160  
2161 =item none example 2
2162  
2163 # given: synopsis;
2164  
2165 my $none = $set->none(sub {
2166 my ($key, $value) = @_;
2167  
2168 $value < 1
2169 });
2170  
2171 # 1
2172  
2173 =back
2174  
2175 =cut
2176  
2177 =head2 one
2178  
2179 one(coderef $code) (boolean)
2180  
2181 The one method returns true if only one of the elements in the array meet the
2182 criteria set by the operand and rvalue.
2183  
2184 I<Since C<4.11>>
2185  
2186 =over 4
2187  
2188 =item one example 1
2189  
2190 # given: synopsis;
2191  
2192 my $one = $set->one(sub {
2193 $_ == 1
2194 });
2195  
2196 # 1
2197  
2198 =back
2199  
2200 =over 4
2201  
2202 =item one example 2
2203  
2204 # given: synopsis;
2205  
2206 my $one = $set->one(sub {
2207 my ($key, $value) = @_;
2208  
2209 $value == 1
2210 });
2211  
2212 # 1
2213  
2214 =back
2215  
2216 =cut
2217  
2218 =head2 order
2219  
2220 order(number @indices) (Venus::Set)
2221  
2222 The order method reorders the array items based on the indices provided and
2223 returns the invocant.
2224  
2225 I<Since C<4.11>>
2226  
2227 =over 4
2228  
2229 =item order example 1
2230  
2231 # given: synopsis;
2232  
2233 my $order = $set->order;
2234  
2235 # bless(..., "Venus::Set")
2236  
2237 # $set->list;
2238  
2239 # [1..9]
2240  
2241 =back
2242  
2243 =over 4
2244  
2245 =item order example 2
2246  
2247 # given: synopsis;
2248  
2249 my $order = $set->order(8,7,6);
2250  
2251 # bless(..., "Venus::Set")
2252  
2253 # $set->list;
2254  
2255 # [9,8,7,1,2,3,4,5,6]
2256  
2257 =back
2258  
2259 =over 4
2260  
2261 =item order example 3
2262  
2263 # given: synopsis;
2264  
2265 my $order = $set->order(0,2,1);
2266  
2267 # bless(..., "Venus::Set")
2268  
2269 # $set->list;
2270  
2271 # [1,3,2,4,5,6,7,8,9]
2272  
2273 =back
2274  
2275 =cut
2276  
2277 =head2 pairs
2278  
2279 pairs() (arrayref)
2280  
2281 The pairs method is an alias to the pairs_array method. This method can return
2282 a list of values in list-context.
2283  
2284 I<Since C<4.11>>
2285  
2286 =over 4
2287  
2288 =item pairs example 1
2289  
2290 # given: synopsis;
2291  
2292 my $pairs = $set->pairs;
2293  
2294 # [
2295 # [0, 1],
2296 # [1, 2],
2297 # [2, 3],
2298 # [3, 4],
2299 # [4, 5],
2300 # [5, 6],
2301 # [6, 7],
2302 # [7, 8],
2303 # [8, 9],
2304 # ]
2305  
2306 =back
2307  
2308 =cut
2309  
2310 =head2 part
2311  
2312 part(coderef $code) (tuple[arrayref, arrayref])
2313  
2314 The part method iterates over each element in the array, executing the code
2315 reference supplied in the argument, using the result of the code reference to
2316 partition to array into two distinct array references. This method can return a
2317 list of values in list-context.
2318  
2319 I<Since C<4.11>>
2320  
2321 =over 4
2322  
2323 =item part example 1
2324  
2325 # given: synopsis;
2326  
2327 my $part = $set->part(sub {
2328 $_ > 5
2329 });
2330  
2331 # [[6..9], [1..5]]
2332  
2333 =back
2334  
2335 =over 4
2336  
2337 =item part example 2
2338  
2339 # given: synopsis;
2340  
2341 my $part = $set->part(sub {
2342 my ($key, $value) = @_;
2343  
2344 $value < 5
2345 });
2346  
2347 # [[1..4], [5..9]]
2348  
2349 =back
2350  
2351 =cut
2352  
2353 =head2 pop
2354  
2355 pop() (any)
2356  
2357 The pop method returns the last element of the array shortening it by one.
2358 Note, this method modifies the array.
2359  
2360 I<Since C<4.11>>
2361  
2362 =over 4
2363  
2364 =item pop example 1
2365  
2366 # given: synopsis;
2367  
2368 my $pop = $set->pop;
2369  
2370 # 9
2371  
2372 =back
2373  
2374 =cut
2375  
2376 =head2 push
2377  
2378 push(any @data) (arrayref)
2379  
2380 The push method appends the array by pushing the agruments onto it and returns
2381 itself.
2382  
2383 I<Since C<4.11>>
2384  
2385 =over 4
2386  
2387 =item push example 1
2388  
2389 # given: synopsis;
2390  
2391 my $push = $set->push(10);
2392  
2393 # [1..10]
2394  
2395 =back
2396  
2397 =cut
2398  
2399 =head2 random
2400  
2401 random() (any)
2402  
2403 The random method returns a random element from the array.
2404  
2405 I<Since C<4.11>>
2406  
2407 =over 4
2408  
2409 =item random example 1
2410  
2411 # given: synopsis;
2412  
2413 my $random = $set->random;
2414  
2415 # 2
2416  
2417 # my $random = $set->random;
2418  
2419 # 1
2420  
2421 =back
2422  
2423 =cut
2424  
2425 =head2 range
2426  
2427 range(number | string @args) (arrayref)
2428  
2429 The range method accepts a I<"range expression"> and returns the result of
2430 calling the L</slice> method with the computed range.
2431  
2432 I<Since C<4.11>>
2433  
2434 =over 4
2435  
2436 =item range example 1
2437  
2438 # given: synopsis
2439  
2440 package main;
2441  
2442 my $range = $set->range;
2443  
2444 # []
2445  
2446 =back
2447  
2448 =over 4
2449  
2450 =item range example 2
2451  
2452 # given: synopsis
2453  
2454 package main;
2455  
2456 my $range = $set->range(0);
2457  
2458 # [1]
2459  
2460 =back
2461  
2462 =over 4
2463  
2464 =item range example 3
2465  
2466 # given: synopsis
2467  
2468 package main;
2469  
2470 my $range = $set->range('0:');
2471  
2472 # [1..9]
2473  
2474 =back
2475  
2476 =over 4
2477  
2478 =item range example 4
2479  
2480 # given: synopsis
2481  
2482 package main;
2483  
2484 my $range = $set->range(':4');
2485  
2486 # [1..5]
2487  
2488 =back
2489  
2490 =over 4
2491  
2492 =item range example 5
2493  
2494 # given: synopsis
2495  
2496 package main;
2497  
2498 my $range = $set->range('8:');
2499  
2500 # [9]
2501  
2502 =back
2503  
2504 =over 4
2505  
2506 =item range example 6
2507  
2508 # given: synopsis
2509  
2510 package main;
2511  
2512 my $range = $set->range('4:');
2513  
2514 # [5..9]
2515  
2516 =back
2517  
2518 =over 4
2519  
2520 =item range example 7
2521  
2522 # given: synopsis
2523  
2524 package main;
2525  
2526 my $range = $set->range('0:2');
2527  
2528 # [1..3]
2529  
2530 =back
2531  
2532 =over 4
2533  
2534 =item range example 8
2535  
2536 # given: synopsis
2537  
2538 package main;
2539  
2540 my $range = $set->range('2:4');
2541  
2542 # [3..5]
2543  
2544 =back
2545  
2546 =over 4
2547  
2548 =item range example 9
2549  
2550 # given: synopsis
2551  
2552 package main;
2553  
2554 my $range = $set->range(0..3);
2555  
2556 # [1..4]
2557  
2558 =back
2559  
2560 =over 4
2561  
2562 =item range example 10
2563  
2564 # given: synopsis
2565  
2566 package main;
2567  
2568 my $range = $set->range('-1:8');
2569  
2570 # [9]
2571  
2572 =back
2573  
2574 =over 4
2575  
2576 =item range example 11
2577  
2578 # given: synopsis
2579  
2580 package main;
2581  
2582 my $range = $set->range('0:8');
2583  
2584 # [1..9]
2585  
2586 =back
2587  
2588 =over 4
2589  
2590 =item range example 12
2591  
2592 # given: synopsis
2593  
2594 package main;
2595  
2596 my $range = $set->range('0:-2');
2597  
2598 # [1..8]
2599  
2600 =back
2601  
2602 =over 4
2603  
2604 =item range example 13
2605  
2606 # given: synopsis
2607  
2608 package main;
2609  
2610 my $range = $set->range('-2:-2');
2611  
2612 # [8]
2613  
2614 =back
2615  
2616 =over 4
2617  
2618 =item range example 14
2619  
2620 # given: synopsis
2621  
2622 package main;
2623  
2624 my $range = $set->range('0:-20');
2625  
2626 # []
2627  
2628 =back
2629  
2630 =over 4
2631  
2632 =item range example 15
2633  
2634 # given: synopsis
2635  
2636 package main;
2637  
2638 my $range = $set->range('-2:-20');
2639  
2640 # []
2641  
2642 =back
2643  
2644 =over 4
2645  
2646 =item range example 16
2647  
2648 # given: synopsis
2649  
2650 package main;
2651  
2652 my $range = $set->range('-2:-6');
2653  
2654 # []
2655  
2656 =back
2657  
2658 =over 4
2659  
2660 =item range example 17
2661  
2662 # given: synopsis
2663  
2664 package main;
2665  
2666 my $range = $set->range('-2:-8');
2667  
2668 # []
2669  
2670 =back
2671  
2672 =over 4
2673  
2674 =item range example 18
2675  
2676 # given: synopsis
2677  
2678 package main;
2679  
2680 my $range = $set->range('-2:-9');
2681  
2682 # []
2683  
2684 =back
2685  
2686 =over 4
2687  
2688 =item range example 19
2689  
2690 # given: synopsis
2691  
2692 package main;
2693  
2694 my $range = $set->range('-5:-1');
2695  
2696 # [5..9]
2697  
2698 =back
2699  
2700 =cut
2701  
2702 =head2 reverse
2703  
2704 reverse() (arrayref)
2705  
2706 The reverse method returns an array reference containing the elements in the
2707 array in reverse order.
2708  
2709 I<Since C<4.11>>
2710  
2711 =over 4
2712  
2713 =item reverse example 1
2714  
2715 # given: synopsis;
2716  
2717 my $reverse = $set->reverse;
2718  
2719 # [9, 8, 7, 6, 5, 4, 3, 2, 1]
2720  
2721 =back
2722  
2723 =cut
2724  
2725 =head2 rotate
2726  
2727 rotate() (arrayref)
2728  
2729 The rotate method rotates the elements in the array such that first elements
2730 becomes the last element and the second element becomes the first element each
2731 time this method is called.
2732  
2733 I<Since C<4.11>>
2734  
2735 =over 4
2736  
2737 =item rotate example 1
2738  
2739 # given: synopsis;
2740  
2741 my $rotate = $set->rotate;
2742  
2743 # [2..9, 1]
2744  
2745 =back
2746  
2747 =cut
2748  
2749 =head2 rsort
2750  
2751 rsort() (arrayref)
2752  
2753 The rsort method returns an array reference containing the values in the array
2754 sorted alphanumerically in reverse.
2755  
2756 I<Since C<4.11>>
2757  
2758 =over 4
2759  
2760 =item rsort example 1
2761  
2762 # given: synopsis;
2763  
2764 my $rsort = $set->rsort;
2765  
2766 # [9, 8, 7, 6, 5, 4, 3, 2, 1]
2767  
2768 =back
2769  
2770 =cut
2771  
2772 =head2 set
2773  
2774 set(any $value) (any)
2775  
2776 The set method inserts a new value into the set if it doesn't exist.
2777  
2778 I<Since C<4.11>>
2779  
2780 =over 4
2781  
2782 =item set example 1
2783  
2784 # given: synopsis
2785  
2786 package main;
2787  
2788 $set = $set->set(10);
2789  
2790 # 10
2791  
2792 =back
2793  
2794 =over 4
2795  
2796 =item set example 2
2797  
2798 # given: synopsis
2799  
2800 package main;
2801  
2802 $set = $set->set(0);
2803  
2804 # 0
2805  
2806 =back
2807  
2808 =cut
2809  
2810 =head2 shift
2811  
2812 shift() (any)
2813  
2814 The shift method returns the first element of the array shortening it by one.
2815  
2816 I<Since C<4.11>>
2817  
2818 =over 4
2819  
2820 =item shift example 1
2821  
2822 # given: synopsis;
2823  
2824 my $shift = $set->shift;
2825  
2826 # 1
2827  
2828 =back
2829  
2830 =cut
2831  
2832 =head2 shuffle
2833  
2834 shuffle() (arrayref)
2835  
2836 The shuffle method returns an array with the items in a randomized order.
2837  
2838 I<Since C<4.11>>
2839  
2840 =over 4
2841  
2842 =item shuffle example 1
2843  
2844 # given: synopsis
2845  
2846 package main;
2847  
2848 my $shuffle = $set->shuffle;
2849  
2850 # [4, 5, 8, 7, 2, 9, 6, 3, 1]
2851  
2852 =back
2853  
2854 =cut
2855  
2856 =head2 slice
2857  
2858 slice(string @keys) (arrayref)
2859  
2860 The slice method returns a hash reference containing the elements in the array
2861 at the index(es) specified in the arguments.
2862  
2863 I<Since C<4.11>>
2864  
2865 =over 4
2866  
2867 =item slice example 1
2868  
2869 # given: synopsis;
2870  
2871 my $slice = $set->slice(2, 4);
2872  
2873 # [3, 5]
2874  
2875 =back
2876  
2877 =cut
2878  
2879 =head2 sort
2880  
2881 sort() (arrayref)
2882  
2883 The sort method returns an array reference containing the values in the array
2884 sorted alphanumerically.
2885  
2886 I<Since C<4.11>>
2887  
2888 =over 4
2889  
2890 =item sort example 1
2891  
2892 package main;
2893  
2894 use Venus::Set;
2895  
2896 my $set = Venus::Set->new(['d','c','b','a']);
2897  
2898 my $sort = $set->sort;
2899  
2900 # ["a".."d"]
2901  
2902 =back
2903  
2904 =cut
2905  
2906 =head2 subset
2907  
2908 subset(arrayref | Venus::Array | Venus::Set $data) (boolean)
2909  
2910 The subset method returns true if all the values provided already exist in the
2911 source.
2912  
2913 I<Since C<4.11>>
2914  
2915 =over 4
2916  
2917 =item subset example 1
2918  
2919 # given: synopsis
2920  
2921 package main;
2922  
2923 my $subset = $set->subset([1..4]);
2924  
2925 # true
2926  
2927 =back
2928  
2929 =over 4
2930  
2931 =item subset example 2
2932  
2933 # given: synopsis
2934  
2935 package main;
2936  
2937 my $subset = $set->subset([1..10]);
2938  
2939 # false
2940  
2941 =back
2942  
2943 =over 4
2944  
2945 =item subset example 3
2946  
2947 # given: synopsis
2948  
2949 package main;
2950  
2951 my $subset = $set->subset([1..9]);
2952  
2953 # true
2954  
2955 =back
2956  
2957 =cut
2958  
2959 =head2 superset
2960  
2961 superset(arrayref | Venus::Array | Venus::Set $data) (boolean)
2962  
2963 The superset method returns true if all the values in the source exists in the
2964 values provided.
2965  
2966 I<Since C<4.11>>
2967  
2968 =over 4
2969  
2970 =item superset example 1
2971  
2972 # given: synopsis
2973  
2974 package main;
2975  
2976 my $superset = $set->superset([1..10]);
2977  
2978 # true
2979  
2980 =back
2981  
2982 =over 4
2983  
2984 =item superset example 2
2985  
2986 # given: synopsis
2987  
2988 package main;
2989  
2990 my $superset = $set->superset([1..9]);
2991  
2992 # false
2993  
2994 =back
2995  
2996 =over 4
2997  
2998 =item superset example 3
2999  
3000 # given: synopsis
3001  
3002 package main;
3003  
3004 my $superset = $set->superset([0..9]);
3005  
3006 # true
3007  
3008 =back
3009  
3010 =cut
3011  
3012 =head2 tail
3013  
3014 tail(number $size) (arrayref)
3015  
3016 The tail method returns the bottommost elements, limited by the desired size
3017 specified.
3018  
3019 I<Since C<4.11>>
3020  
3021 =over 4
3022  
3023 =item tail example 1
3024  
3025 # given: synopsis;
3026  
3027 my $tail = $set->tail;
3028  
3029 # [9]
3030  
3031 =back
3032  
3033 =over 4
3034  
3035 =item tail example 2
3036  
3037 # given: synopsis;
3038  
3039 my $tail = $set->tail(1);
3040  
3041 # [9]
3042  
3043 =back
3044  
3045 =over 4
3046  
3047 =item tail example 3
3048  
3049 # given: synopsis;
3050  
3051 my $tail = $set->tail(2);
3052  
3053 # [8,9]
3054  
3055 =back
3056  
3057 =over 4
3058  
3059 =item tail example 4
3060  
3061 # given: synopsis;
3062  
3063 my $tail = $set->tail(5);
3064  
3065 # [5..9]
3066  
3067 =back
3068  
3069 =over 4
3070  
3071 =item tail example 5
3072  
3073 # given: synopsis;
3074  
3075 my $tail = $set->tail(20);
3076  
3077 # [1..9]
3078  
3079 =back
3080  
3081 =cut
3082  
3083 =head2 unique
3084  
3085 unique() (arrayref)
3086  
3087 The unique method returns an array reference consisting of the unique elements
3088 in the array.
3089  
3090 I<Since C<4.11>>
3091  
3092 =over 4
3093  
3094 =item unique example 1
3095  
3096 package main;
3097  
3098 use Venus::Set;
3099  
3100 my $set = Venus::Set->new([1,1,1,1,2,3,1]);
3101  
3102 my $unique = $set->unique;
3103  
3104 # [1, 2, 3]
3105  
3106 =back
3107  
3108 =cut
3109  
3110 =head2 unshift
3111  
3112 unshift(any @data) (arrayref)
3113  
3114 The unshift method prepends the array by pushing the agruments onto it and
3115 returns itself.
3116  
3117 I<Since C<4.11>>
3118  
3119 =over 4
3120  
3121 =item unshift example 1
3122  
3123 # given: synopsis;
3124  
3125 my $unshift = $set->unshift(-2,-1,0);
3126  
3127 # [-2..9]
3128  
3129 =back
3130  
3131 =cut
3132  
3133 =head1 AUTHORS
3134  
3135 Awncorp, C<awncorp@cpan.org>
3136  
3137 =cut
3138  
3139 =head1 LICENSE
3140  
3141 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
3142  
3143 This program is free software, you can redistribute it and/or modify it under
3144 the terms of the Apache license version 2.0.
3145  
3146 =cut
« blib/lib/Venus/Collect.pm ↑ Summary blib/lib/Venus/Map.pm »