-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Hi @jkoudys ,
Thanks a lot for sharing your super-accurate work.
I have a question concerning Immutability. Presently, you make your collections immutable by calling return new static(SplFixedArray $fixedArray); at each end of mutator methods.
This works perfectly as long as the collection itself as no more property than the content of the $fixedArray parameter.
For example if I extend ImmArray this way :
class MyLovelyCollection extends ImmArray
{
protected $feeling = 'loneliness';
public function __construct($fixedArray, $feeling)
{
$this->feeling = $feeling;
parent::__construct($fixedArray);
}
public function getFeeling()
{
return $this->feeling;
}
}And then call something like
$faces = new MyLovelyCollection([':)', ':/', ':D', 'XD'], 'happiness');
echo $faces->getFeeling() // => 'happiness'
$faces->filter(function($face) {
return ! preg_match("#[^/]$#", $face);
});
echo $faces->getFeeling() // => 'loneliness'Because of this, I cannot use together the quality of your iterable ImmArray (it has no point inside a composition) and some properties (mutable or not) that I would attach to. Simple things like composition becomes super hard due to it.
So, more pragmatically, my question is "Why don't do clone $collection; return $collection->doSomething(); instead of return new static(...);?".
Thanks in advance for your time,
Jean