Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8259493

Browse files
committed
Update README with new funtions
1 parent 0e9a503 commit 8259493

File tree

1 file changed

+196
-0
lines changed

1 file changed

+196
-0
lines changed

README.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ _::each([1, 2, 3], function (int $item) {
4040
- [Array](#array)
4141
- [Collection](#collection)
4242
- [Date](#date)
43+
- [Function](#function)
4344
- [Lang](#lang)
4445
- [Math](#math)
4546
- [Number](#number)
@@ -1523,6 +1524,107 @@ Example:
15231524
zip(['a', 'b'], [1, 2], [true, false])
15241525
// => [['a', 1, true], ['b', 2, false]]
15251526

1527+
```
1528+
### zipObject
1529+
1530+
This method is like `fromPairs` except that it accepts two arrays,
1531+
one of property identifiers and one of corresponding values.
1532+
1533+
1534+
1535+
**Arguments:**
1536+
1537+
@param array $props The property identifiers.
1538+
1539+
@param array $values The property values.
1540+
1541+
1542+
1543+
**Return:**
1544+
1545+
@return object the new object.
1546+
1547+
Example:
1548+
```php
1549+
<?php
1550+
use function _\zipObject;
1551+
1552+
zipObject(['a', 'b'], [1, 2])
1553+
/* => object(stdClass)#210 (2) {
1554+
["a"] => int(1)
1555+
["b"] => int(2)
1556+
}
1557+
*\/
1558+
1559+
```
1560+
### zipObjectDeep
1561+
1562+
This method is like `zipObject` except that it supports property paths.
1563+
1564+
1565+
1566+
**Arguments:**
1567+
1568+
@param array $props The property identifiers.
1569+
1570+
@param array $values The property values.
1571+
1572+
1573+
1574+
**Return:**
1575+
1576+
@return object the new object.
1577+
1578+
Example:
1579+
```php
1580+
<?php
1581+
use function _\zipObjectDeep;
1582+
1583+
zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2])
1584+
/* => class stdClass#20 (1) {
1585+
public $a => class stdClass#19 (1) {
1586+
public $b =>
1587+
array(2) {
1588+
[0] => class stdClass#17 (1) {
1589+
public $c => int(1)
1590+
}
1591+
[1] => class stdClass#18 (1) {
1592+
public $d => int(2)
1593+
}
1594+
}
1595+
}
1596+
}
1597+
*\/
1598+
1599+
```
1600+
### zipWith
1601+
1602+
This method is like `zip` except that it accepts `iteratee` to specify
1603+
how grouped values should be combined. The iteratee is invoked with the
1604+
elements of each group: (.
1605+
1606+
..group).
1607+
1608+
**Arguments:**
1609+
1610+
@param array[] $arrays The arrays to process.
1611+
1612+
@param callable $iteratee The function to combine grouped values.
1613+
1614+
1615+
1616+
**Return:**
1617+
1618+
@return array the new array of grouped elements.
1619+
1620+
Example:
1621+
```php
1622+
<?php
1623+
use function _\zipWith;
1624+
1625+
zipWith([1, 2], [10, 20], [100, 200], function($a, $b, $c) { return $a + $b + $c; })
1626+
// => [111, 222]
1627+
15261628
```
15271629
## Collection
15281630

@@ -1677,9 +1779,103 @@ Example:
16771779
now();
16781780
// => 1511180325735
16791781

1782+
```
1783+
## Function
1784+
1785+
### memoize
1786+
1787+
Creates a function that memoizes the result of `func`. If `resolver` is
1788+
provided, it determines the cache key for storing the result based on the
1789+
arguments provided to the memoized function. By default, the first argument
1790+
provided to the memoized function is used as the map cache key
1791+
1792+
**Note:** The cache is exposed as the `cache` property on the memoized
1793+
function. Its creation may be customized by replacing the `_.memoize.Cache`
1794+
constructor with one whose instances implement the
1795+
[`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
1796+
method interface of `clear`, `delete`, `get`, `has`, and `set`.
1797+
1798+
**Arguments:**
1799+
1800+
@param callable $func The function to have its output memoized.
1801+
1802+
@param callable $resolver The function to resolve the cache key.
1803+
1804+
1805+
1806+
**Return:**
1807+
1808+
@return callable Returns the new memoized function.
1809+
1810+
Example:
1811+
```php
1812+
<?php
1813+
use function _\memoize;
1814+
1815+
$object = ['a' => 1, 'b' => 2];
1816+
$other = ['c' => 3, 'd' => 4];
1817+
1818+
$values = memoize('_\values');
1819+
$values($object);
1820+
// => [1, 2]
1821+
1822+
$values($other);
1823+
// => [3, 4]
1824+
1825+
$object['a'] = 2;
1826+
$values($object);
1827+
// => [1, 2]
1828+
1829+
// Modify the result cache.
1830+
$values->cache->set($object, ['a', 'b']);
1831+
$values($object);
1832+
// => ['a', 'b']
1833+
16801834
```
16811835
## Lang
16821836

1837+
### eq
1838+
1839+
Performs a comparison between two values to determine if they are equivalent.
1840+
1841+
1842+
1843+
**Arguments:**
1844+
1845+
@param mixed $value The value to compare.
1846+
1847+
@param mixed $other The other value to compare.
1848+
1849+
1850+
1851+
**Return:**
1852+
1853+
@return bool Returns `true` if the values are equivalent, else `false`.
1854+
1855+
Example:
1856+
```php
1857+
<?php
1858+
use function _\eq;
1859+
1860+
$object = (object) ['a' => 1];
1861+
$other = (object) ['a' => 1];
1862+
1863+
eq($object, $object);
1864+
// => true
1865+
1866+
eq($object, $other);
1867+
// => false
1868+
1869+
eq('a', 'a');
1870+
// => true
1871+
1872+
eq(['a'], (object) ['a']);
1873+
// => false
1874+
1875+
eq(INF, INF);
1876+
// => true
1877+
1878+
```
16831879
### isEqual
16841880

16851881
Performs a deep comparison between two values to determine if they are

0 commit comments

Comments
 (0)