pipe.dart

Home   »   pipe.dart

import "dart:collection";

void main() {
  const List list = const [1, 2, 3];
  List mutationList = list
    >> (List l) => List.of(l) 
    >> (List l) => l.map((e) => e + 1).toList();
  
  print(list);
  print(mutationList);
  print(list >> (List l) => l.first);
  print(mutationList >> (List l) => l.first);
  
  print('');
  
  const Map map = const {"a": 1, "b": 2, "c": 3};
  Map mutationMap = map 
    >> (Map m) => Map.of(m)
    >> (Map m) => m..updateAll((k, v) => v + 1);

  print(map);
  print(mutationMap);
  print(map >> (Map m) => m.entries.first);
  print(mutationMap >> (Map m) => m.entries.first);
}

// ---------------------- Iterable -----------------------------------

extension IterablePiping on Iterable {
  /// Places the left-side `Iterable x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(Iterable) f) => f(this);
}

// ---------------------- Map -----------------------------------

extension MapPiping on Map {
  /// Places the left-side `Map x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(Map) f) => f(this);
}

extension HashMapPiping on HashMap {
  /// Places the left-side `HashMap x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(HashMap) f) => f(this);
}

extension LinkedHashMapPiping on LinkedHashMap {
  /// Places the left-side `LinkedHashMap x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(LinkedHashMap) f) => f(this);
}

extension SplayTreeMapPiping on SplayTreeMap {
  /// Places the left-side `SplayTreeMap x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(SplayTreeMap) f) => f(this);
}

extension UnmodifiableMapViewPiping on UnmodifiableMapView {
  /// Places the left-side `UnmodifiableMapView x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(UnmodifiableMapView) f) => f(this);
}

// ---------------------- List -----------------------------------

extension ListPiping on List {
  /// Places the left-side `List x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(List) f) => f(this);
}

extension LinkedListPiping> on LinkedList {
  /// Places the left-side `LinkedList x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(LinkedList) f) => f(this);
}

extension LinkedListEntryPiping>
    on LinkedListEntry {
  /// Places the left-side `LinkedListEntry x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(LinkedListEntry) f) => f(this);
}

extension ListQueuePiping on ListQueue {
  /// Places the left-side `ListQueue x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(ListQueue) f) => f(this);
}

extension QueuePiping on Queue {
  /// Places the left-side `Queue x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(Queue) f) => f(this);
}

extension DoubleLinkedQueuePiping on DoubleLinkedQueue {
  /// Places the left-side `DoubleLinkedQueue x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(DoubleLinkedQueue) f) => f(this);
}

extension DoubleLinkedQueueEntryPiping on DoubleLinkedQueueEntry {
  /// Places the left-side `DoubleLinkedQueueEntry x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(DoubleLinkedQueueEntry) f) => f(this);
}

extension UnmodifiableListViewPiping on UnmodifiableListView {
  /// Places the left-side `UnmodifiableListView x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(UnmodifiableListView) f) => f(this);
}

// ---------------------- Set -----------------------------------

extension SetPiping on Set {
  /// Places the left-side `Set x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(Set) f) => f(this);
}

extension HashSetPiping on HashSet {
  /// Places the left-side `HashSet x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(HashSet) f) => f(this);
}

extension LinkedHashSetPiping on LinkedHashSet {
  /// Places the left-side `LinkedHashSet x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(LinkedHashSet) f) => f(this);
}

extension SplayTreeSetPiping on SplayTreeSet {
  /// Places the left-side `SplayTreeSet x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(SplayTreeSet) f) => f(this);
}

extension UnmodifiableSetViewPiping on UnmodifiableSetView {
  /// Places the left-side `UnmodifiableSetView x` into right-side `Function f` as single argument.
  /// Returns the function result `f(x)`
  T operator >>(T Function(UnmodifiableSetView) f) => f(this);
}

Leave a Reply

Your email address will not be published. Required fields are marked *