Closed munificent closed 9 years ago
Removed Type-Defect label. Added Type-Enhancement label.
Ran into this today. It would be nice to be able to, say, find the .dart files in a list of arguments. args.where((each) => '.dart'.hasMatch(each)) The alternatives are both more awkward to write and less efficient.
The problem is that adding more methods to Pattern also means adding them to String, and the name generally don't look as fitting on a String as on a more specialized pattern.
The solution is usually to use the "reverse method" on String: args.where((each) => each.contains(".dart")); // or even .endsWith(...)
Methods on Pattern/RegExp often exists to support methods on String, so there is usually a corresponding method on string that takes a Pattern which should not be awkward (if it is, do speak up!)
Added NotPlanned label.
Both String and RegExp implement Pattern, which is awesome. You can generically treat a String as if it were a RegExp... except that Pattern doesn't have all of the methods that RegExp provides. Pattern mysteriously leaves off hasMatch, firstMatch, and stringMatch, which means String also lacks them.