Skip to content

Commit a388878

Browse files
committed
removed obsolete helper function
1 parent 91c2ac6 commit a388878

File tree

14 files changed

+51
-33
lines changed

14 files changed

+51
-33
lines changed

Examples/Chapter08/LINQ/EnumerableExamples.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ public static void SimpleSelectManyExample()
3939
var a =
4040
from c in Range('a', 'c')
4141
from i in Range(2, 3)
42-
select Tuple(c, i);
42+
select (c, i);
4343

4444
var b =
4545
Range('a', 'c')
4646
.SelectMany(c => Range(2, 3)
47-
.Select(i => Tuple(c, i)));
47+
.Select(i => (c, i)));
4848

4949
var d = Range('a', 'c')
5050
.SelectMany(c => Range(2, 3)
51-
, (c, i) => Tuple(c, i));
51+
, (c, i) => (c, i));
5252

5353

5454

Examples/Chapter08/LINQ/OptionExamples.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ public static void SimpleSelectManyExample()
140140
var a =
141141
from c in Range('a', 'c')
142142
from i in Range(1, 2)
143-
select Tuple(c, i);
143+
select (c, i);
144144

145145
var b =
146146
Range('a', 'c')
147147
.SelectMany(c => Range(1, 2)
148-
.Select(i => Tuple(c, i)));
148+
.Select(i => (c, i)));
149149

150150
a.ForEach(t => WriteLine($"({t.Item1}, {t.Item2})"));
151151
WriteLine();

Examples/Chapter09/Monkeys.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@ string DescribeChoiceOf_Dull(Reward reward)
4848
throw new InvalidOperationException("Unknown reward");
4949
}
5050

51+
string DescribeWithIs(Reward reward)
52+
{
53+
if (reward is Banana banana)
54+
return $"It's a {banana.Ripeness} banana";
55+
56+
else if (reward is Peanut _)
57+
return "It's a peanut";
58+
59+
return "It's a reward I don't know or care about";
60+
}
61+
62+
string DescribeWithSwitch(Reward reward)
63+
{
64+
switch (reward)
65+
{
66+
case Banana banana:
67+
return $"It's a {banana.Ripeness} banana";
68+
case Peanut _:
69+
return "It's a peanut";
70+
default:
71+
return "It's a reward I don't know or care about";
72+
}
73+
}
74+
5175
string DescribeChoiceOf(Reward reward)
5276
=> reward.Match(
5377
Peanut: () => "It's a peanut",

Examples/Chapter10/Domain/Account.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static class Account
2525
var evt = cmd.ToEvent();
2626
var newState = @this.Apply(evt);
2727

28-
return Tuple(evt as Event, newState);
28+
return (evt as Event, newState);
2929
}
3030

3131
public static Validation<(Event Event, AccountState NewState)> Freeze
@@ -37,7 +37,7 @@ public static class Account
3737
var evt = cmd.ToEvent();
3838
var newState = @this.Apply(evt);
3939

40-
return Tuple(evt as Event, newState);
40+
return (evt as Event, newState);
4141
}
4242

4343
// apply events

Examples/Chapter10/Transitions/Account.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static Transition<AccountState, CreatedAccount>
1818
{
1919
var evt = cmd.ToEvent();
2020
var newState = evt.ToAccount();
21-
return Tuple(evt, newState);
21+
return (evt, newState);
2222
};
2323

2424

@@ -32,7 +32,7 @@ public static Transition<AccountState, DepositedCash>
3232
var evt = cmd.ToEvent();
3333
var newState = account.Apply(evt);
3434

35-
return Tuple(evt, newState);
35+
return (evt, newState);
3636
};
3737

3838
public static Transition<AccountState, AlteredOverdraft>
@@ -42,7 +42,7 @@ public static Transition<AccountState, AlteredOverdraft>
4242
var evt = cmd.ToEvent(cmd.Amount - account.AllowedOverdraft);
4343
var newState = account.Apply(evt);
4444

45-
return Tuple(evt, newState);
45+
return (evt, newState);
4646
};
4747

4848
public static Validation<FrozeAccount> Freeze

Examples/Chapter10/Transitions/Transition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static Transition<St, R> Select<St, T, R>
1313
(this Transition<St, T> transition, Func<T, R> project)
1414
=> state0
1515
=> transition(state0)
16-
.Map(result => Tuple(project(result.Item1), result.Item2));
16+
.Map(result => (project(result.Item1), result.Item2));
1717

1818
public static Transition<St, R> SelectMany<St, T, R>
1919
(this Transition<St, T> transition, Func<T, Transition<St, R>> f)
@@ -32,7 +32,7 @@ public static Transition<St, RR> SelectMany<St, T, R, RR>
3232
=> state0
3333
=> transition(state0)
3434
.Bind(t => bind(t.Item1)(t.Item2)
35-
.Map(r => Tuple(project(t.Item1, r.Item1), r.Item2)));
35+
.Map(r => (project(t.Item1, r.Item1), r.Item2)));
3636

3737
// var(r, state2) = bind(t)(state1);
3838
// var rr = project(t, r);

Examples/Chapter14/CurrencyLookup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ public static void _main()
128128
// if (tpl.Item1.ContainsKey(pair))
129129
// {
130130
// WriteLine("reusing cached value");
131-
// return Tuple(tpl.Item1, tpl.Item1[pair].ToString());
131+
// return (tpl.Item1, tpl.Item1[pair].ToString());
132132
// }
133133
// else
134134
// {
135135
// WriteLine("fetching remotely...");
136136
// return Yahoo.GetRate(pair)
137-
// .Map(rate => Tuple(tpl.Item1.Add(pair, rate), rate.ToString()))
138-
// .Recover(ex => Tuple(tpl.Item1, ex.Message))
137+
// .Map(rate => (tpl.Item1.Add(pair, rate), rate.ToString()))
138+
// .Recover(ex => (tpl.Item1, ex.Message))
139139
// .Result;
140140
// }
141141
// });

Examples/Chapter15/Agents/Counter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void PrintThreadOf(string op)
1616
{
1717
var newState = state + msg;
1818
PrintThreadOf("Counter");
19-
return Tuple(newState, newState);
19+
return (newState, newState);
2020
});
2121

2222
// public interface of the Counter

Examples/Chapter15/Boc/AccountProcess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public AccountProcess(AccountState initialState, Func<Event, Task<Unit>> saveAnd
3030
await result.Traverse(tpl => saveAndPublish(tpl.Event)); // persist within block, so that the agent doesn't process new messages in a non-persisted state
3131

3232
var newState = result.Map(tpl => tpl.NewState).GetOrElse(state);
33-
return Tuple(newState, result);
33+
return (newState, result);
3434
});
3535
}
3636

Examples/Chapter15/Boc/AccountRegistry.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ public AccountRegistry_Naive(Func<Guid, Task<Option<AccountState>>> loadAccount
2323
{
2424
AccountProcess account;
2525
if (cache.TryGetValue(id, out account))
26-
return Tuple(cache, Some(account));
26+
return (cache, Some(account));
2727

2828
var optAccount = await loadAccount(id);
2929

3030
return optAccount.Map(accState =>
3131
{
3232
var process = new AccountProcess(accState, saveAndPublish);
33-
return Tuple(cache.Add(id, process), Some(process));
33+
return (cache.Add(id, process), Some(process));
3434
})
35-
.GetOrElse(() => Tuple(cache, (Option<AccountProcess>)None));
35+
.GetOrElse(() => (cache, (Option<AccountProcess>)None));
3636
});
3737
}
3838

@@ -59,14 +59,14 @@ public AccountRegistry(Func<Guid, Task<Option<AccountState>>> loadAccount
5959
this.agent = Agent.Start(AccountsCache.Empty, (AccountsCache cache, Msg msg) =>
6060
new Pattern<ValueTuple<AccountsCache, Option<AccountProcess>>>
6161
{
62-
(LookupMsg m) => Tuple(cache, cache.Lookup(m.Id)),
62+
(LookupMsg m) => (cache, cache.Lookup(m.Id)),
6363

6464
(RegisterMsg m) => cache.Lookup(m.Id).Match(
65-
Some: acc => Tuple(cache, Some(acc)),
65+
Some: acc => (cache, Some(acc)),
6666
None: () =>
6767
{
6868
var account = new AccountProcess(m.AccountState, saveAndPublish);
69-
return Tuple(cache.Add(m.Id, account), Some(account));
69+
return (cache.Add(m.Id, account), Some(account));
7070
})
7171
}
7272
.Match(msg));

0 commit comments

Comments
 (0)