pipe 1.2.0 copy "pipe: ^1.2.0" to clipboard
pipe: ^1.2.0 copied to clipboard

outdated

Pipe operator for some basic Dart types.

example/pipe_example.dart

import 'package:pipe/pipe.dart';

void main() {
  /// `String`:
  var str1 = 'Hello' | print; // Hello 
  
  // str1 has dynamic type here.
  print(str1); // Hello

  // Chain of pipes:
  // ( str2 has type String here)
  String str2 = 'Hello' | (s) => '$s, man!' | print; // Hello, man!

  /// `List`:
  var list = [1, 2, 3] | print; // [1, 2, 3]
  print(list); // [1, 2, 3]

  /// `Map` and `Set` literals may produce syntax error:
  // {'a':123} | print; // syntax error
  // {1,2,3} | print; // syntax error
  // Use variables in this case:

  var m = {'a': 123};
  m | print; // {a: 123}

  var s = {1, 2, 3};
  s | print; // {1, 2, 3}

  // Only single-argument functions are supported.
  // But you can go that way:

  /// Two arguments function:
  String concat(String a, String b) => a+b;
  
  'Hello' | (a) => concat(a, '!') | print; // Hello!

}
5
likes
20
pub points
22%
popularity

Publisher

unverified uploader

Pipe operator for some basic Dart types.

Homepage

License

unknown (LICENSE)

More

Packages that depend on pipe