@@ 11-32 (lines=22) @@ | ||
8 | use Zicht\Itertools\conversions; |
|
9 | use Zicht\Itertools\lib\DifferenceIterator; |
|
10 | ||
11 | trait DifferenceTrait |
|
12 | { |
|
13 | /** |
|
14 | * Returns a DifferenceIterator containing elements in $this but not in $iterable |
|
15 | * |
|
16 | * @param array|string|\Iterator $iterable |
|
17 | * @param null|string|\Closure $strategy Optional |
|
18 | * @return null|DifferenceIterator |
|
19 | */ |
|
20 | public function difference($iterable, $strategy = null) |
|
21 | { |
|
22 | if ($this instanceof \Iterator) { |
|
23 | return new DifferenceIterator( |
|
24 | $this, |
|
25 | conversions\mixed_to_iterator($iterable), |
|
26 | conversions\mixed_to_value_getter($strategy) |
|
27 | ); |
|
28 | } |
|
29 | ||
30 | return null; |
|
31 | } |
|
32 | } |
|
33 |
@@ 11-32 (lines=22) @@ | ||
8 | use Zicht\Itertools\conversions; |
|
9 | use Zicht\Itertools\lib\IntersectionIterator; |
|
10 | ||
11 | trait IntersectionTrait |
|
12 | { |
|
13 | /** |
|
14 | * Returns an IntersectionIterator containing elements in $this that are also in $iterable |
|
15 | * |
|
16 | * @param array|string|\Iterator $iterable |
|
17 | * @param null|string|\Closure $strategy Optional |
|
18 | * @return null|IntersectionIterator |
|
19 | */ |
|
20 | public function intersection($iterable, $strategy = null) |
|
21 | { |
|
22 | if ($this instanceof \Iterator) { |
|
23 | return new IntersectionIterator( |
|
24 | $this, |
|
25 | conversions\mixed_to_iterator($iterable), |
|
26 | conversions\mixed_to_value_getter($strategy) |
|
27 | ); |
|
28 | } |
|
29 | ||
30 | return null; |
|
31 | } |
|
32 | } |
|
33 |