dagolden / Path-Tiny

File path utility
41 stars 59 forks source link

RFC: `with( $callback )` method #256

Closed ap closed 1 year ago

ap commented 2 years ago

@xdg wrote:

I decided to just call it mkdir and call out why it's different than the built-in in the documentation.

Nice! I like that a lot.

Previously:

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.

xdg commented 1 year ago

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