Another idea -- probably terrible -- would be a way to embed a different chain within a chain:
In fact I thought of this myself. I don’t think it is necessarily terrible at all.
Is that even Tiny?
Not only would I say it is, it even seems to me that more Tiny than anything. After all it lets you do things with the P::T instance, in the middle of a method chain called on it, without P::T itself having any methods to do those things.
Case in point, if you want the behaviour of the mkdir built-in rather than the new mkdir method, but you want it in the middle of a chain that you don’t want to break into separate statements (possibly because you want to put the chain in the middle of another expression (e.g. a function call)), you can just insert →with(sub{ mkdir $_ }) or something along these lines.
The one disparity this example brings up is the question of error checking. Perhaps with should expect its callback to return true, and automatically treat a false return as an error.
I must add I am not firmly sold on the whole idea (and certainly feeling no kind of urgency about its addition!) – there just seems to be enough to it that I don’t want to see it lost as a mere tangent in some since-resolved issues.
On reflection, I don't think adding this is a good addition to the API. (There's already the assert method that can sort of be abused in this way if someone really wanted to.)
@xdg wrote:
Nice! I like that a lot.
Previously:
In fact I thought of this myself. I don’t think it is necessarily terrible at all.
Not only would I say it is, it even seems to me that more Tiny than anything. After all it lets you do things with the P::T instance, in the middle of a method chain called on it, without P::T itself having any methods to do those things.
Case in point, if you want the behaviour of the
mkdir
built-in rather than the newmkdir
method, but you want it in the middle of a chain that you don’t want to break into separate statements (possibly because you want to put the chain in the middle of another expression (e.g. a function call)), you can just insert→with(sub{ mkdir $_ })
or something along these lines.The one disparity this example brings up is the question of error checking. Perhaps
with
should expect its callback to return true, and automatically treat a false return as an error.I must add I am not firmly sold on the whole idea (and certainly feeling no kind of urgency about its addition!) – there just seems to be enough to it that I don’t want to see it lost as a mere tangent in some since-resolved issues.