mpetrovich / dash Goto Github PK
View Code? Open in Web Editor NEWA functional programming library for PHP. Inspired by Underscore, Lodash, and Ramda.
Home Page: https://github.com/mpetrovich/dash/blob/main/docs/Operations.md
License: MIT License
A functional programming library for PHP. Inspired by Underscore, Lodash, and Ramda.
Home Page: https://github.com/mpetrovich/dash/blob/main/docs/Operations.md
License: MIT License
When accessing array keys or object properties that share the same name as a global function (eg. abs
), the global function is referenced/returned instead of the appropriate array/object value. This affects a number of operations including get()
, map()
, and property()
.
$this->assertSame(
['a', 'b', 'c'],
Dash\map([
['abs' => 'a'],
['abs' => 'b'],
['abs' => 'c'],
], 'abs')
);
$this->assertSame(
'value',
Dash\get(['abs' => 'value'], 'abs')
);
$this->assertSame(
'value',
call_user_func(Dash\property('abs'), ['abs' => 'value'])
);
Hey
my code is
$content = _::chain($input)
->filter(function ($i) {
return $i['action_name'] === "type1" ? true : false;
})
->map(function ($i) {
return getHTML($i['banner']);
})
->join('')
->value();
echo $content;
I used join in chain but i get fatal error
PHP Fatal error: Uncaught InvalidArgumentException: Dash\\join expects iterable or stdClass or null but was given string
usort()
doesn't work natively with decimal values. Details: https://stackoverflow.com/questions/16520000/usort-issue-with-decimal-numbers
It's good sugar
I need the mathematical set theory union basically.
Dash::union (
[1, 3, 5],
[1 ,3 ,7 ],
[7, 8] );
Expected output 1,3,5,1,3,7,7,8
clamp($v, $min, $max) returns $min if $v < $min
$max if $v > $max
$v if $min <= $v <= $max
Operators like filter
and map
take an iterable
but return an array
. All values of the iterable
have to be iterated during evaluation. The following example will run out of memory because ints
is an infinite iterable
:
function ints() {
$counter = 0;
while (true) {
yield $counter;
++$counter;
}
}
$result = Dash\_chain(ints())
->filter('Dash\isEven')
->take(3)
->join(', ')
->value();
The same works fine if you use iterables
as intermediate results like nikic/iter does
$result = iter\join(', ',
iter\take(3,
iter\filter('Dash\isEven',
ints())));
Hey, Thanks for new features you added so far.
Still I need compose
function, It Will be great if you add it.
Ramda Compose
There is a type error when using the operator get for PHP8.
Problem:
src/hasDirect.php in method_exists at line 36
Lines 27 to 37 in bd6ec10
I mean the example is similar to 'curry'. Shouldn't curryRight's arguments applied in reverse order?
Is there anything against releasing version 1.0.0 (see How do I know when to release 1.0.0?)?
If curry()
is called with an array-style callable (eg. [$this, 'sum']
), an exception is thrown:
TypeError: ReflectionFunction::__construct() expects parameter 1 to be string, array given
class curryTest extends PHPUnit_Framework_TestCase
{
public function sum($a, $b)
{
return $a + $b;
}
public function test()
{
$callable = [$this, 'sum'];
$curried = Dash\curry($callable);
$curried = $curried(1);
$this->assertSame(3, $curried(2));
}
}
It should return something to the effect of:
Dash\map($iterable, Dash\Curry\result($path, $default));
Example:
$array = $array = [
['fn' => function() { ... }],
['fn' => function() { ... }],
['fn' => function() { ... }],
];
$fns = Dash\map($array, 'fn');
$results = Dash\mapResult($array, 'fn');
It could be easier to reject items that strictly equal a given static value. Example:
Dash\filter(
['a', 'b', 'c', 'd, 'c', 'e'],
['c']
);
// === ['a', 'b', 'd', 'e']
$sub = function($a, $b) { return $a - $b; };
$cSub = _::curry($sub);
$cSub(9)(5); //result = 4
_::setCustom('sub', $cSub );
$flSub = _::curryRight($sub);
$flSub(9)(5); // result = -4
_::setCustom('flsub', $flSub );
_::chain(9)->sub(5)->run(); //result = 4
_::chain(9)->flsub(5)->run(); //result = 4
On the last line shouldn't it be "-4" or am I missing something?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.