tapper 1.1.2 tapper: ^1.1.2 copied to clipboard
Provides extension methods on all types to allow inspection/mutation (tap), transformation (pipe), null chaining (zip), and converting (conv)
// ignore_for_file: unused_local_variable
import 'package:rust/rust.dart';
import 'package:tapper/tapper.dart';
void main() {
int? number = 10;
number = number.tap((n) => ++n).tap((n) => print("The number is $n"));
// Prints: The number is 10
number.pipe((n) => ++n).pipe((n) {
print("The number is $n");
return n;
});
// Prints: The number is 11
if (getName()
?.pipe((e) => e.zip(getPreferences()))
?.pipe((e) => e.zip(getDetails()))
case (String name, String preferences, String details)) {
print(
"Hello $name, your preferences are $preferences and details are $details");
} else {
return;
}
// vs
String? name = getName();
if (name == null) {
return;
}
String? preferences = getPreferences();
if (preferences == null) {
return;
}
String? details = getDetails();
if (details == null) {
return;
}
print(
"Hello $name, your preferences are $preferences and details are $details");
String numericString = "123";
number = numericString.convInt(); // convInt exists for this type
// number is now 123
Object nonNumericString = "abc";
Result<int, TryConvError> numberResult = nonNumericString.tryConv<int>();
// conversion is not possible and handled with Result
List<Set<List<int>>> nestedInt = [
{
[1]
}
];
Result<String, TryConvError> stringResult = nestedInt.tryConv<String>();
// result is Ok("1")
}
String? getName() => "John";
String? getPreferences() => "Preferences";
String? getDetails() => "Details";