map<O> method
Returns a ReadableBeacon that wraps a Beacon and tranforms its values.
final count = Beacon.writable(10);
final mapped = count.map((value) => value * 2);
expect(mapped.value, 20);
count.value = 20;
expect(count.value, 20);
expect(mapped.value, 40);
Implementation
ReadableBeacon<O> map<O>(
MapFilter<T, O> mapFN, {
String? name,
}) {
assert(
this is! BufferedBaseBeacon,
'''
Chaining of buffered beacons is not supported!
Buffered beacons has to be the last in the chain.
Good: someBeacon.map().buffer(10);
Bad: someBeacon.buffer(10).map();
''',
);
final beacon = _MappedBeacon(mapFN, name: name);
_wrapThis(beacon);
return beacon;
}