Reference Wrapper | Coderz Product

reference_wrapper

Last updated:

0 purchases

reference_wrapper Image
reference_wrapper Images

Free

Languages

Categories

Add to Cart

Description:

reference wrapper

Reference Wrapper is a Dart package which simulates pass by reference feature using Wrapper class which holds the value.
Usage #

Use this package if you are calling a function that needs to modify its arguments

There are two ways to read / write the value #
var x = Ref<num?>(null);
var read1 = x.ref; // first way to read
var read2 = x(); // second way to read

x.ref = 10; // first way to write
x(10); // second way to write
copied to clipboard
Example #
void twice(Ref<num> x, Ref<num> y) {
x.ref *= 2;
y.ref *= 2;
}

void test() {
var x = Ref<num>(5);
var y = Ref<num>(7);

twice(x, y);
print(x.ref); // 10
print(y.ref); // 14
}
copied to clipboard
Advanced Example #
void twice(Ref<num> x, Ref<num> y) {
x(x() * 2);
y(y() * 2);
}

void test() {
var x = Ref<num>(5);
var y = Ref<num>(7);

twice(x, y);
print(x()); // 10
print(y()); // 14
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product: (if this is empty don't purchase this product)

Customer Reviews

There are no reviews.