tapper 1.1.0 copy "tapper: ^1.1.0" to clipboard
tapper: ^1.1.0 copied to clipboard

Provides extension methods on all types to allow inspection/mutation (tap), transformation (pipe), null chaining (zip), and converting (conv)

example/main.dart

// ignore_for_file: unused_local_variable

import 'package:rust_core/result.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";
4
likes
0
pub points
53%
popularity

Publisher

verified publishervoyver.com

Provides extension methods on all types to allow inspection/mutation (tap), transformation (pipe), null chaining (zip), and converting (conv)

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

rust_core

More

Packages that depend on tapper