2017 © Pedro Peláez
 

library immutable

Immutable PHP primitive wrappers

image

innmind/immutable

Immutable PHP primitive wrappers

  • Thursday, April 12, 2018
  • by Baptouuuu
  • Repository
  • 1 Watchers
  • 6 Stars
  • 4,561 Installations
  • PHP
  • 46 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 41 Versions
  • 5 % Grown

The README.md

Immutable

Build Status codecov Type Coverage, (*1)

A set of classes to wrap PHP primitives to build immutable data., (*2)

Documentation, (*3)

Installation

composer require innmind/immutable

Usage

Here are some examples of what you can do:, (*4)

Sequence

To be used to wrap an ordered list of elements (elements can be of mixed types)., (*5)

use Innmind\Immutable\Sequence;

$seq = Sequence::of(24, 42, 'Hitchhiker', 'Magrathea');
$seq->get(2); // Maybe::just(Hitchhiker)
$another = $seq->drop(2);
$another->toList(); // [Hitchhiker, Magrathea]
$seq->toList(); // [24, 42, Hitchhiker, Magrathea]

//----
// this example demonstrates the lazyness capability of the sequence
// precisely here it's able to read a file line by line and echo the lines
// that are less than 42 characters long (without requiring to load the whole
// file in memory)
$someFile = fopen('some/file.txt', 'r');
$lines = Sequence::lazy(fn() => yield fgets($someFile))
    ->filter(fn($line) => strlen($line) < 42);
// at this point no reading to the file has been done because all methods
// returning a new instance of a sequence will pipeline the operations to do,
// allowing to chain complex logic while accessing the original data once and
// without the need to keep the discarded data along the pipeline in memory
$lines->foreach(fn($line) => echo($line));

For a complete list of methods check Sequence., (*6)

Set

To be used as a collection of unordered elements (elements must be of the same type)., (*7)

use Innmind\Immutable\Set;

$set = Set::of(24, 42);
$set->equals(Set::of(24, 42)); // true
$set->add(42.0); // psalm will raise an error

For a complete list of methods check Set., (*8)

Map

To be used as a collection of key/value pairs (both keys and values must be of the same type)., (*9)

use Innmind\Immutable\Map;

$map = Map::of(
    [new \stdClass, 42]
    [$key = new \stdClass, 24]
);
$map->size(); // 2, because it's 2 different instances
$map->values()->toList(); // [42, 24]
$map = $map->put($key, 66);
$map->size(); // 2
$map->values()->toList(); // [42, 66]

For a complete list of methods check Map., (*10)

Strings

use Innmind\Immutable\Str;

$var = Str::of('the hitchhiker\'s guide to the galaxy');
echo $var
    ->replace('galaxy', '42') // the hitchhiker's guide to the 42
    ->drop(18) // guide to the 42
    ->toUpper()
    ->toString(); // outputs: GUIDE TO THE 42
echo $var->toString(); // outputs: the hitchhiker\'s guide to the galaxy

Regular expressions

use Innmind\Immutable\{
    RegExp,
    Str,
};

$regexp = RegExp::of('/(?<i>\d+)/');
$regexp->matches(Str::of('foo123bar')); // true
$regexp->matches(Str::of('foobar')); // false
$regexp->capture(Str::of('foo123bar')); // Map<int|string, Str> with index `i` set to Str::of('123')

BlackBox

This library provides 2 Sets that can be used with innmind/black-box., (*11)

You can use them as follow:, (*12)

use Innmind\BlackBox\{
    PHPUnit\BlackBox,
    Set,
};
use Fixtures\Innmind\Immutable;

class SomeTest extends \PHPUnit\Framework\TestCase
{
    use BlackBox;

    public function testSomeProperty()
    {
        $this
            ->forAll(
                Immutable\Set::of(
                    Set\RealNumbers::any(),
                ),
                Immutable\Sequence::of(
                    Set\Uuid::any(),
                ),
            )
            ->then(function($set, $sequence) {
                // $set is an instance of \Innmind\Immutable\Set<float>
                // $sequence is an instance of \Innmind\Immutable\Sequence<string>

                // write your test here
            });
    }
}

The Versions

12/04 2018

dev-develop

dev-develop http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

25/02 2018

dev-master

9999999-dev http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

25/02 2018

2.8.0

2.8.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

28/01 2018

2.7.4

2.7.4.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

28/01 2018

2.7.3

2.7.3.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

28/01 2018

2.7.2

2.7.2.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

28/01 2018

2.7.1

2.7.1.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

17/12 2017

2.7.0

2.7.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

23/11 2017

2.6.0

2.6.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

07/10 2017

2.5.0

2.5.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

30/09 2017

2.4.1

2.4.1.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

06/08 2017

2.4.0

2.4.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

23/07 2017

2.3.1

2.3.1.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

21/05 2017

2.3.0

2.3.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

19/02 2017

2.2.1

2.2.1.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

19/02 2017

2.2.0

2.2.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

14/02 2017

2.1.0

2.1.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

14/02 2017

2.0.1

2.0.1.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

12/02 2017

2.0.0

2.0.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

05/02 2017

1.12.0

1.12.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

04/02 2017

1.11.0

1.11.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

04/02 2017

1.10.0

1.10.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

The Development Requires

wrapper immutable

15/07 2016

1.9.0

1.9.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

05/05 2016

1.8.0

1.8.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

05/05 2016

1.7.0

1.7.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

23/04 2016

1.6.0

1.6.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

11/04 2016

1.5.2

1.5.2.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

17/03 2016

1.5.1

1.5.1.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

05/03 2016

1.5.0

1.5.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

24/02 2016

1.4.0

1.4.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

18/02 2016

1.3.0

1.3.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

15/02 2016

1.2.0

1.2.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

07/02 2016

1.1.1

1.1.1.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

05/02 2016

1.1.0

1.1.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

04/02 2016

1.0.0

1.0.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php ~7.0

 

wrapper immutable

17/01 2016

0.10.0

0.10.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php >=5.6

 

wrapper immutable

17/01 2016

0.9.0

0.9.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php >=5.6

 

wrapper immutable

16/01 2016

0.8.0

0.8.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php >=5.6

 

wrapper immutable

14/01 2016

0.7.0

0.7.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php >=5.6

 

wrapper immutable

11/01 2016

0.6.0

0.6.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php >=5.6

 

wrapper immutable

09/01 2016

0.5.0

0.5.0.0 http://github.com/Innmind/Immutable

Immutable PHP primitive wrappers

  Sources   Download

MIT

The Requires

  • php >=5.6

 

wrapper immutable