Pretty print Dart collections

Thanks to a recent commit from Josh Bloch, you can now pretty print your Dart collections. This makes debugging and scripts much easier to write.


main() {
  var list = [1,2,3];
  print("List: $list");

  var map = {"hello": "world", "1": 1};
  print("Map: $map");

  var set = new Set();
  print("Set: $set");

The VM's old 'n busted results:

List: [1, 2, 3, ]
Map: Instance of 'LinkedHashMapImplementation'
Set: Instance of 'HashSetImplementation<Dynamic>'

The VM's new hotness results:

List: [1, 2, 3]
Map: {hello: world, 1: 1}
Set: {bar, foo}


That's pretty, but what about something tough? How does it handle recursive references?

print("Recursive list: $list");

Old 'n busted:

[I never let it stop running, totally busted]

New hotness:

Recursive list: [1, 2, 3, [...]]

You'll need the very latest source from the bleed_edge branch to see this in action. It won't be long until this lands in trunk, though.


Popular posts from this blog

Lists and arrays in Dart

Converting Array to List in Scala

Null-aware operators in Dart