Your code calls for your duty! Write clear, efficient code with this library.
This library is divided into seven parts:
This part includes the basic
Monad class for all monads.
Option is a class representing the presence or the absence of a value.
The presence is indicated by the class
Some and the absence is represented
None, an instance of class nothing.
Option can be used in conjunction
duty.Map or with
This part comes with a better implementation of a map: The
WrappedMap is an
Tuple2s. It enables O(1) access to values by keys.
DefaultMap behaves like
Map but if a value is not present, the configurable
default function of the map is invoked and returns a value.
A library part made for pattern matching.
match(arg, PartialFunction pf), a pattern match can be started.
A partial function is a function that is defined for some input arguments
and for some not. To easily create a partial function, call the
when(condition) method. This returns a
A condition can be either a constant or a
Predicate, functions of form
bool test(arg) =>. They match if the function returns true or if the
constant is equal to the argument.
If a function is defined on an input argument, its body is invoked. The
body is a
Then, either a function of type
(arg) => value or a constant.
Evaluatables contains a value that is either a function of form
() => or
an other value. If the value is a function,
evaluate returns its result.
Otherwise, it returns the value directly.
Tuples are typesafe containers for one or more values. Currently,
Tuple3 are implemented.
Control flow implementations are in this part of the library.
IfElse consists of a
Condition and an
ifBody and an
call() evaluates to the result of the
ifBody if the condition evaluates
to true and the
When is like
ifElse but it only has a
body. It returns an
which is either
Some if the
When was true and None otherwise.
Result is the result of a computation which can be either a
Failure. This wraps the
try-catch construct inside program logic.
To wrap a closure of form
() => into either a
Success or a
pass it to
util.dart comes with several utility functions:
n(num a) wraps a
num inside a
Numeric container. This offers
functions such as
times which executes a given function
Numeric is a shorthand for
until invoked on a
Numeric return a
NumericRangeExclusive. These Ranges provide lazy iterables, as such
it is possible to define ranges like
n(0).to(double.INFINITY). For a range,
a step width can be additionally specified, defaulting to
flatten flattens a nested list. Additionally, a
level can be specified
how deep the flattening is applied. For negative numbers, the flattening
flattens all nested lists.
equalLists checks if two lists are equal. Nested lists are also checked
with this method.
reverse reverses the given argument in a correct manner:
If the argument is a
String, a string with the characters reversed is returned.
If the argument is an
int, the int is first converted to a
then reversed and then parsed as an
int. The same applies for
Iterables are converted to a list which is then reversed.
max extracts the maximum value out of an iterable with comparables.
min extracts the minimum.
avg calculates the average of a list of