internal async Task Observers_Should_Not_Receive_Dispatched_Actions_After_Disposing_Subscription() { var changeInt = new ChangeInt(5); var changeBool = new ChangeBool(true); var observedActionsA = new List <object>(); var observedActionsB = new List <object>(); var subscriptionA = _store.Observe().Subscribe(observedActionsA.Add); var subscriptionB = _store.Observe().Subscribe(observedActionsB.Add); await _store.Dispatch(changeInt); observedActionsA.ShouldBe(new object[] { changeInt }); observedActionsB.ShouldBe(new object[] { changeInt }); subscriptionA.Dispose(); await _store.Dispatch(changeBool); observedActionsA.ShouldBe(new object[] { changeInt }); observedActionsB.ShouldBe(new object[] { changeInt, changeBool }); subscriptionB.Dispose(); await _store.Dispatch(new object()); observedActionsA.ShouldBe(new object[] { changeInt }); observedActionsB.ShouldBe(new object[] { changeInt, changeBool }); }
static void Main(string[] args) { // LINQ on a simple array.. string [] names = {"cat", "dog", "mouse", "rat"}; IEnumerable<string> expr = from s in names where s.Length == 3 orderby s select s.ToUpper(); foreach(string item in expr) { Console.WriteLine(item); } // lambda expression syntax // first.. basic delegate.. ChangeInt myDoubler = new ChangeInt(Program.DoubleIt); Console.WriteLine(myDoubler(4)); // now the same, using a lambda expression.. ChangeInt myTripler = x => x*3; Console.WriteLine(myTripler(4)); // lambda syntax: // <argname> => <some function that permutes <argname>> // typed lambda.. ChangeInt myQuadrupler = (int x) => x*4; Console.WriteLine(myQuadrupler(4)); // two parameter type lambda expression TwoIntFunction MultNums = (int x,int y) => x*y; Console.WriteLine(String.Format(" 4*5 = {0}",MultNums(4,5))); // now the same examples, using Functional Generics provided by LINQ.. // use of: // public delegate TR Func<T0,TR>(T0 a0); // Func<int,int> myTripler2 = x => x*3; Console.WriteLine(myTripler(6)); // lambda syntax: // <argname> => <some function that permutes <argname>> // typed lambda.. // use of: // public delegate TR Func<T0,TR>(T0 a0); // Func<int,int> myQuadrupler2 = (int x) => x*4; Console.WriteLine(myQuadrupler(6)); // two parameter type lambda expression // use of: // public delegate TR Func<T0,T1,TR>(T0 a0,T1 a1); // Func<int,int,int> MultNums2 = (int x,int y) => x*y; Console.WriteLine(String.Format(" 7*8 = {0}",MultNums(7,8))); }
public BasePropertyChanger GetPropertyChanger() { ChangeInt result = new ChangeInt(); if (int.TryParse(tbxValue.Text.Trim(), out int value)) { result.SetValue(value); } return(result); }
internal async Task Store_Should_Allow_Asynchronous_Handling_Of_Dispatched_Actions() { var tcs = new TaskCompletionSource <object>(); Task HandleDispatchedAction(object action) { tcs.SetResult(action); return(Task.CompletedTask); } _store.Subscribe <object>(HandleDispatchedAction); var dispatchedAction = new ChangeInt(5); await _store.Dispatch(dispatchedAction); var receivedAction = await tcs.Task; receivedAction.ShouldBe(dispatchedAction); }
private void button1_Click(object sender, EventArgs e) { ChangeInt d = new ChangeInt(Tang2); label1.Text = d(20).ToString(); ChangeInt d2 = k => k + 2; label2.Text = d2(20).ToString(); ChangeInt d2a = (int x) => x + 2; label3.Text = d2a(20).ToString(); ChangeInt d3 = delegate(int x) { return(x + 2); }; label4.Text = d3(20).ToString(); Tong d5 = (x, y) => x + y; label5.Text = d5(20, 20).ToString(); Tong d6 = new Tong((x, y) => x - y); label6.Text = d6(20, 10).ToString(); }
internal async Task Subscribers_Should_Only_Receive_Actions_Of_Type_They_Subscribe_To() { var tcs = new TaskCompletionSource <object>(); Task HandleDispatchedChangeBoolAction(ChangeBool changeBoolAction) { tcs.SetResult(changeBoolAction); return(Task.CompletedTask); } _store.Subscribe <ChangeBool>(HandleDispatchedChangeBoolAction); var changeInt = new ChangeInt(5); var changeBool = new ChangeBool(true); await _store.Dispatch(changeInt); await _store.Dispatch(changeBool); var receivedAction = await tcs.Task; receivedAction.ShouldBe(changeBool); }