Skip to content

Commit f1b4302

Browse files
committed
Simplified method names
1 parent cbe3a20 commit f1b4302

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/IterableObject.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct($iterable, $filter = null, $map = null)
6565
* @param callable $filter
6666
* @return self
6767
*/
68-
public function withFilter($filter)
68+
public function filter($filter)
6969
{
7070
return new self($this->iterable, $filter, $this->map);
7171
}
@@ -74,11 +74,31 @@ public function withFilter($filter)
7474
* @param callable $map
7575
* @return self
7676
*/
77-
public function withMap($map)
77+
public function map($map)
7878
{
7979
return new self($this->iterable, $this->filter, $map);
8080
}
8181

82+
/**
83+
* @param callable $filter
84+
* @return self
85+
* @deprecated Use IterableObject::filter instead.
86+
*/
87+
public function withFilter($filter)
88+
{
89+
return $this->filter($filter);
90+
}
91+
92+
/**
93+
* @param callable $map
94+
* @return self
95+
* @deprecated Use IterableObject::map instead.
96+
*/
97+
public function withMap($map)
98+
{
99+
return $this->map($map);
100+
}
101+
82102
/**
83103
* @inheritdoc
84104
*/

tests/TestIterableObject.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ public function testFilterAndMapMutators()
6767
$map = 'strtoupper';
6868
$iterableObject = iterable(array('foo', 'bar'))->withMap($map)->withFilter($filter);
6969
$this->assertEquals(array(1 => 'BAR'), iterator_to_array($iterableObject));
70+
$iterableObject = iterable(array('foo', 'bar'))->map($map)->filter($filter);
71+
$this->assertEquals(array(1 => 'BAR'), iterator_to_array($iterableObject));
7072
$iterableObject = iterable(array('foo', 'bar'))->withFilter($filter)->withMap($map);
7173
$this->assertEquals(array(1 => 'BAR'), iterator_to_array($iterableObject));
74+
$iterableObject = iterable(array('foo', 'bar'))->filter($filter)->map($map);
75+
$this->assertEquals(array(1 => 'BAR'), iterator_to_array($iterableObject));
7276
}
7377

7478
public function dataProvider()
@@ -107,4 +111,4 @@ public function dataProvider()
107111
);
108112
}
109113

110-
}
114+
}

0 commit comments

Comments
 (0)