On Thu, Aug 18, 2016 at 8:56 PM, Alexandru Ermicioi via Digitalmars-d-announce <[email protected]> wrote:
> On Tuesday, 16 August 2016 at 19:24:22 UTC, Rory McGuire wrote: > >> On 16 Aug 2016 20:45, "Alexandru Ermicioi via Digitalmars-d-announce" < >> [email protected]> wrote: >> >>> >>> On Tuesday, 16 August 2016 at 14:25:10 UTC, Jacob Carlborg wrote: >>> >>>> >>>> On 2016-08-16 11:41, Alexandru Ermicioi wrote: >>>> >>>> https://github.com/aermicioi/aedi >>>>> >>>> >>>> >>>> If you use: >>>> >>>> ```d >>>> ``` >>>> >>>> For the code block you'll get syntax highlighting for D. >>>> >>> >>> >>> Thx, for info. Didn't know about such syntax. I'll update it with next >>> >> batch of modifications. >> >> Can this be used to do function >> currying? http://stackoverflow.com/questions/36314/what-is-currying >> >> Seems like an interesting feature. I imagine it would use templates or a >> wrapper struct instead of wrapped functions though. >> > > Thank you, for sharing with an idea :) > > I'm not sure if I understand your proposition correctly. > > I assume that you meant the call of register function on container to > register an object in it. If so, by applying currying, we would get > something like: > > container.register!Type()("constructor")("setter", "setterArg"); // And > so on. > > It's an interesting idea, but I'm not sure if it will allow an easy > customization of register api :(. > > Could you please explain it in more detail? > No probs, example: ///// module m1; /// this module contains standard functions / classes etc... auto func1(Type1 v1, Type2 v2, Type3 v3) { // do awesome stuff with all three instances } class A { Type4 v4; Type5 v5; this(Type4 v4, Type5 v5) { this.v4 =v4; this.v5=v5; } void changeMode(Type2 v2) { v4.asdf(v2); } void opApply(...) { /// do normal stuff with all these manually passed in instances } } module auto_deps_m1; /// this module has the curryied versions of the original functions and classes from m1; /// What I think would be cool, and I thinks its possible, would be to automatically inject default instance parameters into classes (the Object), and functions. /// so func1 could for example be exposed in this module as: auto func1(Type2 v2) { /// yeah, don't worry about passing the other stuff in, it was all setup during dependency registration } class A { Type4 v4; /// inject this Type5 v5; this(Type5 v5) { this.v5 = v5; // we never registered a Type5 during dependency registration this.v4.changeMode(registered_v2); /// this got moved here due to compile time dependency registration } void opApply(...) { // do stuff, and all we had to supply in other modules that depend on this one is the instance for v5 } } ////// The function example is what I was thinking initially, but I don't see why it couldn't be done with structs and classes as well. I guess in m2 the code the programmer writes would be similar to: mixin(registrationService.ct_register!(func1)); etc.. If its not possible right now I'd imagine its fairly close to possible. disclaimer: I'm not very familiar with dependency injection in anything but Javascript with AngularJS.
