Module handles functions and templates that we lazied to factor out to separate module.
Function categories:
Deserializes from Json to type T
Supported only structs yet
struct S { @required int a; //get value from Json. Throws RequiredFieldException @possible int b; //tries to get value from Json int c; //will be ignored } auto s = deserializeFromJson!S(json);
Serializes struct with @required attributes fields to Json
Example
struct S { @required int a = 1; //will be used @possible int b = 2; //will be ignored int c; //will be ignored } writeln(serializeRequiredToJson(S())); // { "a":1 }
Tries to call function. On exception throws Ex, otherwise return func() result
Tries to evaluate par. On exception throws Ex, otherwise return par
cast to shared type T
cast to unqual type T
Retrieves member type with name of class Class. If member is agregate type declaration or simply doesn't exist, retrieves no type. You can check it with is operator.
class A { int aField; string b; bool c; class B {} struct C {} union D {} interface E {} } static assert(is(getMemberType!(A, "aField") == int)); static assert(is(getMemberType!(A, "b") == string)); static assert(is(getMemberType!(A, "c") == bool)); static assert(!is(getMemberType!(A, "B"))); static assert(!is(getMemberType!(A, "C"))); static assert(!is(getMemberType!(A, "D"))); static assert(!is(getMemberType!(A, "E")));
Retrieves names of all class/struct/union Class fields excluding technical ones like this, Monitor.
class A { int aField; void func1() {} static void func2() {} string b; final func3() {} abstract void func4(); bool c; } static assert(FieldNameTuple!A == ["aField","b","c"]);
Removes one element from the list
NEVER use while iterating the list.
Struct-wrapper to handle result of computations, that can fail.
class A {} auto a = new A(); auto ma = Maybe!A(a); auto mb = Maybe!A(null); assert(!ma.isNothing); assert(mb.isNothing); assert(ma.get == a); assertThrown!Error(mb.get); bool ncase = false, jcase = false; ma.map(() {ncase = true;}, (v) {jcase = true;}); assert(jcase && !ncase); ncase = jcase = false; mb.map(() {ncase = true;}, (v) {jcase = true;}); assert(!jcase && ncase);
Alias to stored type
Constructing Maybe from value. If pointer is null methods: isNothing returns true and get throws Error.
Constructing empty Maybe. If Maybe is created with the method, it is considred empty and isNothing returns false.
Returns true if stored value is null
Unwrap value from Maybe. If stored value is null, Error is thrown.
Unwrap value from Maybe. If stored value is null, Error is thrown.
If struct holds null, then nothingCase result is returned. If struct holds not null value, then result is returned. justCase is fed with unwrapped value.
If struct holds null, then nothingCase result is returned. If struct holds not null value, then result is returned. justCase is fed with unwrapped value.
Struct-wrapper to handle result of computations, that can fail.
struct A {} auto ma = Maybe!A(A()); auto mb = Maybe!A.nothing; assert(!ma.isNothing); assert(mb.isNothing); assert(ma.get == A()); assertThrown!Error(mb.get); bool ncase = false, jcase = false; ma.map(() {ncase = true;}, (v) {jcase = true;}); assert(jcase && !ncase); ncase = jcase = false; mb.map(() {ncase = true;}, (v) {jcase = true;}); assert(!jcase && ncase);
Alias to stored type
Constructing empty Maybe. If Maybe is created with the method, it is considred empty and isNothing returns false.
Constructing Maybe from value. If Maybe is created with the constructor, it is considered non empty and isNothing returns false.
Returns true if stored value is null
Unwrap value from Maybe. If the Maybe is empty, Error is thrown.
Unwrap value from Maybe. If the Maybe is empty, Error is thrown.
If struct holds null, then nothingCase result is returned. If struct holds not null value, then result is returned. justCase is fed with unwrapped value.
If struct holds null, then nothingCase result is returned. If struct holds not null value, then result is returned. justCase is fed with unwrapped value.
Transforms delegate into lazy range. Generation is stopped, when genfunc returns Maybe!T.nothing.
assert( (() => Maybe!int(1)).generator.take(10).equal(1.repeat.take(10)) ); assert( (() => Maybe!int.nothing).generator.empty); assert( (() { static size_t i = 0; return i++ < 10 ? Maybe!int(1) : Maybe!int.nothing; } ).generator.equal(1.repeat.take(10))); class A {} auto a = new A(); assert( (() => Maybe!A(a)).generator.take(10).equal(a.repeat.take(10)) ); assert( (() => Maybe!A.nothing).generator.empty); assert( (() { static size_t i = 0; return i++ < 10 ? Maybe!A(a) : Maybe!A.nothing; } ).generator.equal(a.repeat.take(10)));
Allows to fast retreiving results from functions that returns a tuple.
Tuple!(int, string) foo() { return tuple(1, "a"); } int x; string y; tie!(x,y) = foo(); assert(x == 1 && y == "a");