dartlin 0.2.0+1 dartlin: ^0.2.0+1 copied to clipboard
Dartlin is a helper library that provides readable methods with which you can write cleaner looking code.
dartlin #
Introduction #
What it does #
Dartlin is a helper library that provides readable methods with which you can write cleaner looking code.
- It allows you to have more control over your code flow. By using the
when
method for example, to write switch-like expressions. - It provides methods to create data sets of certain types, for example the
range
method.
What does it not do #
Dartlin is by definition not a performance optimization library, the main focus is adding readable methods that help you keep your code clean. And readability does not always equal performance optimization. So if you are looking to optimize your code, this is not the library for you.
Note: The performance hit of the provided methods tends to be very minimal, but most of them do rely on closures to work.
Common Usage #
Control flow #
The Dartlin control_flow
library provides methods for writing cleaner and more controllable code, these control flow methods can be used as a replacement for existing control flow statements or in combination with them.
Note: Dart already provides a few interesting control flow operations for List
s and Map
s. So before you decide to use Dartlin, first read more about Collection operators. It may already suit your needs.
iff
, if-statement as expressions
The iff
method works like the if statement, but with the added bonus of being able to write them as expressions. You can use them to replace complex ternary operators with a readable if-like statement:
var x = iff(a < b, () {
return a;
}).elseIf(a == b, () {
return 0;
}).orElse(() {
return b;
});
See the iff docs for more information.
when
, switch statement
The when
method replaces the switch statement. And can be used to write expressions:
final result = when(place, {
1: () => CompetitionPlace.first,
2: () => CompetitionPlace.second,
3: () => CompetitionPlace.third,
[4,5]: () => CompetitionPlace.honourableMentions,
orElse: () => CompetitionPlace.others
});
See the when docs for more information.
Development and Contributing #
Interested in contributing? We love merge requests! See the Contribution guidelines.