Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit 2c9cc00

Browse files
committed
update ...
1 parent 2463d22 commit 2c9cc00

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

src/Collections/LiteCollection.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,37 @@ public function replace(array $items)
6060
}
6161
}
6262

63+
/**
64+
* @param callable $callback
65+
* @return static
66+
*/
67+
public function map(callable $callback)
68+
{
69+
$data = [];
70+
71+
foreach ($this as $key => $value) {
72+
$data[$key] = $callback($value, $key);
73+
}
74+
75+
return new static($data);
76+
}
77+
78+
/**
79+
* @param string $char
80+
* @return string
81+
*/
82+
public function implode($char = ',')
83+
{
84+
$string = '';
85+
86+
foreach ($this as $key => $value) {
87+
// $string .= is_array($value) ? $this->implode($char, $value) : implode($char, $value);
88+
$string .= implode($char, $value);
89+
}
90+
91+
return $string;
92+
}
93+
6394
/**
6495
* {@inheritDoc}
6596
*/

src/Collections/SimpleCollection.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,37 @@ public function sets(array $data)
123123
return $this;
124124
}
125125

126+
/**
127+
* @param callable $callback
128+
* @return static
129+
*/
130+
public function map(callable $callback)
131+
{
132+
$data = [];
133+
134+
foreach ($this->getIterator() as $key => $value) {
135+
$data[$key] = $callback($value, $key);
136+
}
137+
138+
return new static($data);
139+
}
140+
141+
/**
142+
* @param string $char
143+
* @return string
144+
*/
145+
public function implode($char = ',')
146+
{
147+
$string = '';
148+
149+
foreach ($this->getIterator() as $key => $value) {
150+
// $string .= is_array($value) ? $this->implode($char, $value) : implode($char, $value);
151+
$string .= implode($char, $value);
152+
}
153+
154+
return $string;
155+
}
156+
126157
/**
127158
* Get all items in collection
128159
* @return array The collection's source data

src/functions.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ function env(string $name, $default = null)
6666
}
6767
}
6868

69+
if (!function_exists('collect')) {
70+
function collect(array $values)
71+
{
72+
return new \Inhere\Library\Collections\LiteCollection($values);
73+
}
74+
}
75+
6976
if (!function_exists('msleep')) {
7077
function msleep($ms)
7178
{

0 commit comments

Comments
 (0)