Lambda
and StatefulLambda
are the primary way to write commands in
Mercurial.
These classes are immutable command builders, that allow you to compose a
command programmatically, and are easy to read and use.
StatefulLambda
is the same as Lambda
, but has additional state stored in it,
that gets passed to each of its methods to manipulate.
Both Lambda
and StatefulLambda
start with sensible defaults:
Lambda
and StatefulLambda
are easy to construct:
StatefulLambda
will have a RefCell
with a String
in it as its state.
Go read the RefCell
documentation in Util for how it works. We need a cell or
similar in order to obtain interior mutability for a simpler piece of data like
a String
, but you could use a more complex class you’ve written yourself.
Lambda
or StatefulLambda
command.
Lambda.from(Command)
, it does not create a new object
if the argument is already a Lambda
or a StatefulLambda
.
But StatefulLamba.from(Command, STATE)
does not have this safety.
Lambda
and StatefulLambda
are clearly nice and easy ways to compose
commands! They are the recommended tool for writing commands in Mercurial.