generic method for transforming values into new immutable values
misfo opened this issue · comments
Hamster::Immutable
has a succinct and generic way of producing new immutable values based on existing ones. The method is called transform and it allows you to mutate an object within a block which is then frozen to produce the value that's returned.
It'd be nice if this project exposed a method for producing new values like that. Is that something you'd accept a patch for?
Actually Hamster::Immutable
was my initial inspiration for Virtus::Immutable
, which is what this was extracted from.
I would support this kind of method. Is #transform
the best name for it? I'm not saying it's not a good name, I just like to think about API changes and not blindly copy another API without putting as much thought in as if I was designing it from scratch.
Yeah, it seems like there's no standard word in programming for the create-a-new-value-based-on-another-value operation...
How about "beget"? or "produce"?
Hmm. I'm not so sure about those. I kind of like to use terms that are either in common use in the domain, or in common use within natural language. EDIT: well I guess produce is in common use, but not beget.
I wonder if there are any common names in the functional programming world for this kind of thing?
FP peeps seem to just use the word "update" accompanied by some air quotes or asterisks
Sent from my phone
On Oct 10, 2012, at 11:37 PM, Dan Kubb notifications@github.com wrote:
Hmm. I'm not so sure about those. I kind of like to use terms that are either in common use in the domain, or in common use within natural language.
I wonder if there are any common names in the functional programming world for this kind of thing?
—
Reply to this email directly or view it on GitHub.
I actually wouldn't have a problem with #update
as the method name.
FWIW I am planning on adding the protected methods #transform
and #transform_unless
from hamster: https://github.com/harukizaemon/hamster/blob/master/lib/hamster/immutable.rb#L67-L75
@misfo I have added Adamantium#transform
and Adamantium#transform_unless
to the master branch, which were inspired by hamster.
@dkubb If we have transform_unless
shouldnt we also have transform_if
?