Hacker News new | ask | show | jobs
by oblique63 4314 days ago
> I think I'd miss patterns like `if (arr.length) { ... }`

At least for this particular example, dart supports an 'isNotEmpty' property on all iterables[0], so it'd just be this:

    if (arr.isNotEmpty) { ... }
The core libraries support a lot of useful properties like that.

[0] https://api.dartlang.org/apidocs/channels/stable/dartdoc-vie...

1 comments

It's actually important to prefer .isNotEmpty over .length here. In some iterables (think generators, or sequences transformed by higher-order functions), calculating the length requires traversing the entire sequence where .isNotEmpty can stop after finding a single item.