DEV Community

Cover image for Dart - Cascade Notation
Shahzaib Noor
Shahzaib Noor

Posted on

 

Dart - Cascade Notation

Remember those days in different languages when you are utilising an object and you need to call methods with that object multiple times. Cascade Notation is denoted using a pair of dots(..), pseudo code will clear things a bit more.

Object..method1()..method2()

Now object can be anything like List, Maps etc. Let's look at the sample code then things will become more clear.

var f1 = {1: 'Apple', 2: 'Orange'};
var f2 = {3: 'Banana'};
var f3 = {4: 'Mango'};
var fruit = {}..addAll(f1)..addAll(f2)..addAll(f3);
print('Merging maps using cascade notation: $fruit');
Enter fullscreen mode Exit fullscreen mode

In the code above, we see cascade notation of dart in action. It is allowing us to perform sequence of operations with repeating code, as a result our code is compact and eye pleasing. I hope you enjoyed this little episode of Dart till next time take care and see you guys soon ๐Ÿ˜Š

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesnโ€™t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.