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