cascade operator or nearest equivalent
Daniel Davidson
nospam at spam.com
Thu Sep 12 12:34:15 PDT 2013
Is there any way to simulate the cascade operator (..) of Dart in
D? This operator makes fluid initialization simple.
I am using Dart for code generation but would like to consider D
if I can find a convenient replacement for the following
declarative style:
var dateRange = struct('date_range')
..doc = 'Basic pair of start and end dates'
..unitTest = true
..publicSection = true
..members = [
member('start_date')
..type = 'Date',
member('end_date')
..type = 'Date',
];
So struct is a function that returns an instance of Struct.
class Struct extends Decls {
...
/// Documentation for this D struct
String doc;
/// List of members of this class
List<Member> members = [];
bool unitTest = false;
...
}
..doc = ... assigns to the Struct.doc field and returns the
original Struct instance so that ..unitTest = true can be applied
to the original Struct instance, etc.
What is the best way to achieve simple declarative style for very
large initialization objects?
Thanks,
Dan
More information about the Digitalmars-d-learn
mailing list