Re: readonly member (but assignable at constructor time)

2018-04-27 Thread lempiji via Digitalmars-d-learn

On Friday, 27 April 2018 at 02:59:16 UTC, Dr.No wrote:
In C# you can have a readonly member assignable either at 
declaration or constructor time, like this:


class C
{
  readonly myClass mc;

  this()
  {
mc = new myClass();
  }


  void doSomething()
  {
mc = new myClass(); // wrong! result in compiler error, mc 
is readonly

  }
}

Does D have something like this natively or there's a way to do 
so with traits/CTFE at runtime?


You can use std.experimenta.typecons.Final.
https://dlang.org/phobos/std_experimental_typecons.html#.Final


Re: Reactive data

2018-03-31 Thread lempiji via Digitalmars-d-learn

On Friday, 23 March 2018 at 12:59:23 UTC, crimaniak wrote:

I want to have reactive variables like in this example:

```
USING_REACTIVE_DOMAIN(D)

// The two words
VarSignalT firstWord  = MakeVar(string( "Change" ));
VarSignalT secondWord = MakeVar(string( "me!" ));
// ...
SignalT bothWords = firstWord + string( " " ) + 
secondWord;

```

from this page: 
http://schlangster.github.io/cpp.react/tutorials/BasicSignals.html


Is this possible to make it in D with 
https://github.com/lempiji/rx ? Is there other libraries exists 
for this topic?


I think that it can use combineLatest which was recently added.
If using 'alias this' or 'operator overloading', might look like 
more original example.


---
import rx;

auto firstWord = new BehaviorSubject!string("Change");
auto secondWord = new BehaviorSubject!string("me!");

auto bothWords = new BehaviorSubject!string("");
combineLatest!((a, b) => a ~ " " ~ b)(firstWord, 
secondWord).doSubscribe(bothWords);


writeln(bothWords.value); // Change me!

firstWord.value = "TEST";
writeln(bothWords.value); // TEST me!
---