pipe 1.2.0 pipe: ^1.2.0 copied to clipboard
Pipe operator for some basic Dart types.
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!
}