language agnostic - Does this higher order function have a name? -


i see pattern everywhere in code, , in libraries, yet there appears no name or abstraction of can find anywhere.

example (pseudocode)

t foo( t x, void f(t&) ) {     t y = x;     f( y );     return y; } 

basically: take value, , function transforms value. make of copy of value, transform it, , return it.

real-life examples (c++)

t operator+(const t& x, const t& y) {     t z = x; // make copy     operator+=(z, y); // modify in place     return z; }  vector3 vector3::normalized() const {     vector3 x = *this; // make copy     x.normalize(); // modify in place     return x; }  t sorted(t const& x) {     t y = x; // make copy (yeah, yeah, have passed value)     sort( y ); // modify in place     return y; } 

basically, have in place function (with side-effects) , make out-of-place function (without side-effects) out of it.

is there name pattern? know of libraries or languages use it? functional languages won't use because don't have referentially opaque functions begin with.

it's in mathematics , fp called composition, because express mystery_function(x, fun) = fun(copy(x)) instead.

in design patterns linguo, it's wrapper, wraps function call copy. rather naturally call copy wrapper. never saw classified anywhere.


Comments

Popular posts from this blog

SAP Web Service from .NET via WCF -

Optimized Line drawing in QT -

datetime - str to time in python -