Giter VIP home page Giter VIP logo

dash's People

Contributors

brandonramirez avatar dantswain avatar dependabot[bot] avatar mpetrovich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dash's Issues

Global functions shouldn't take precedence over array keys or object properties

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().

Test cases

$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'])
);

Fatal error on chain method join

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

Add clamp()

clamp($v, $min, $max) returns $min if $v < $min
                              $max if $v > $max
                              $v if $min <= $v <= $max

Support generators

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())));

PHP 8 error: method_exists(): Argument #1 ($object_or_class) must be of type object|string, array given

There is a type error when using the operator get for PHP8.

Problem:
src/hasDirect.php in method_exists at line 36

dash/src/hasDirect.php

Lines 27 to 37 in bd6ec10

function hasDirect($input, $key)
{
if (!is_string($key) && !is_numeric($key) && !is_null($key)) {
return false;
}
return is_array($input) && array_key_exists($key, $input)
|| is_object($input) && property_exists($input, $key)
|| $input instanceof \ArrayAccess && $input->offsetExists($key)
|| method_exists($input, $key);
}

curry() breaks with array callables

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

Test case

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));
	}
}

Add Dash\mapResult($iterable, $path, $default)

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');

Cannot use curry right inside chain properly.

$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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.