pipe 2.0.0 copy "pipe: ^2.0.0" to clipboard
pipe: ^2.0.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 
  
  print(str1); // Hello

  // If you want to pipe value through function 
  //  and to return result of function call - use `|` opearator.
  // Else if you want to call side-effect function 
  //  on value and return the same value - use `/` operator. 
  
  // Sample.
  // Chain of pipes:
  String str2 = 'Hello' | (s) => '$s, man!' / print; // Hello, man!

  print(str2); // 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
0
pub points
23%
popularity

Publisher

unverified uploader

Pipe operator for some basic Dart types.

Homepage

License

unknown (LICENSE)

More

Packages that depend on pipe