2017 © Pedro Peláez
 

library collection

The fastest collection(array_map, array_reduce, ..) wrapper

image

spindle/collection

The fastest collection(array_map, array_reduce, ..) wrapper

  • Monday, June 26, 2017
  • by hirak
  • Repository
  • 2 Watchers
  • 18 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

spindle/collection

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

The fastest collection library, (*2)

  • construct code and run with eval()
  • very quick & low memory usage
  • You must not pass user's input to this library. It might causes code injection vulnerability.

Usage

composer require 'spindle/collection'
<?php
require_once 'vendor/autoload.php';

use Spindle\Collection\Collection as _;

_::range(1, 100)
    ->filter('$_ % 2')
    ->map('$_ * 2')
    ->assignTo($val);

var_dump($val->toArray());

Methods

map($fn)

_::range(1,4)->map('$_ * 2')->dump();
// 2,4,6,8

filter($fn)

  • $fn($_) == true ==> remain
  • $fn($_) == false ==> remove
_::range(1,4)->filter('$_ % 2')->dump();
// 1,3

reject($fn)

  • $fn($_) == true ==> remove
  • $fn($_) == false ==> remain
_::range(1,4)->reject('$_ % 2')->dump();
// 2,4

unique()

_::from([1,1,2,1])->unique()->dump();
// 1

column(array|string $columns)

Inspired by array_column., (*3)

$a = ['a' => 1, 'b' => 2, 'c' => 3];

_::from([$a, $a])->column(['a', 'c'])->dump();
// ['a' => 1, 'c' => 3], ['a' => 1, 'c' => 3];

_::from([$a, $a])->column('a')->dump();
// 1, 1;

_::from([$a, $a])->column(['a'])->dump();
// ['a' => 1], ['a' => 1]

slice($offset, $length = null)

chunk($size)

reduce($fn, $initial = null)

not chainable, (*4)

$max = _::from([1,2,3,4])->reduce('$_ > $_carry ? $_ : $_carry');

sum()

product()

flip()

exchange value and key., (*5)

_::from(['a' => 1, 'b' => 2, 'c' => 3])->flip()->dump();
// [1 => 'a', 2 => 'b', 3 => 'c'];

sort($sort_flags = \SORT_REGULAR)

rsort($sort_flags = \SORT_REGULAR)

usort(callable $cmp)

assignTo(&$val)

export to variable, (*6)

$val = _::from([1,2,3])->map('$_ * 2');
// equals
_::from([1,2,3])->map('$_ * 2')->assignTo($val);

dump()

$_->dump();
// equals
var_dump($_->toArray());

The Versions

26/06 2017

dev-master

9999999-dev

The fastest collection(array_map, array_reduce, ..) wrapper

  Sources   Download

CC0-1.0

The Requires

  • php >=5.6

 

The Development Requires

by Hiraku NAKANO

25/06 2017

0.0.3

0.0.3.0

The fastest collection(array_map, array_reduce, ..) wrapper

  Sources   Download

CC0-1.0

The Requires

  • php >=5.6

 

The Development Requires

by Hiraku NAKANO

18/06 2017

0.0.1

0.0.1.0

The fastest collection(array_map, array_reduce, ..) wrapper

  Sources   Download

CC0-1.0

The Requires

 

The Development Requires

by Hiraku NAKANO