Skip to content

Commit 14c6550

Browse files
committed
removed explicit uses of ValueTuple type
1 parent a388878 commit 14c6550

File tree

6 files changed

+21
-30
lines changed

6 files changed

+21
-30
lines changed

Examples/Chapter10/Transitions/Transition.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Boc.Chapter10
77
{
8-
public delegate Validation<ValueTuple<T, St>> Transition<St, T>(St state);
8+
public delegate Validation<(T, St)> Transition<St, T>(St state);
99

1010
public static class Transition
1111
{
@@ -21,10 +21,6 @@ public static Transition<St, R> SelectMany<St, T, R>
2121
=> transition(state0)
2222
.Bind(t => f(t.Item1)(t.Item2));
2323

24-
// var(t, state1) = StatefulComputation(state0);
25-
// return f(t)(state1);
26-
//};
27-
2824
public static Transition<St, RR> SelectMany<St, T, R, RR>
2925
(this Transition<St, T> transition
3026
, Func<T, Transition<St, R>> bind
@@ -33,10 +29,5 @@ public static Transition<St, RR> SelectMany<St, T, R, RR>
3329
=> transition(state0)
3430
.Bind(t => bind(t.Item1)(t.Item2)
3531
.Map(r => (project(t.Item1, r.Item1), r.Item2)));
36-
37-
// var(r, state2) = bind(t)(state1);
38-
// var rr = project(t, r);
39-
// return (rr, state2);
40-
//};
4132
}
4233
}

Examples/Chapter12/Trade.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct State
4242
public Bid Bid { get; set; }
4343
public IEnumerable<Offer> Offers { get; set; }
4444

45-
public static implicit operator State(ValueTuple<Bid, IEnumerable<Offer>> t)
45+
public static implicit operator State((Bid, IEnumerable<Offer>) t)
4646
=> new State
4747
{
4848
Bid = t.Item1,

Examples/Chapter15/Boc/AccountRegistry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public AccountRegistry(Func<Guid, Task<Option<AccountState>>> loadAccount
5757
this.loadAccount = loadAccount;
5858

5959
this.agent = Agent.Start(AccountsCache.Empty, (AccountsCache cache, Msg msg) =>
60-
new Pattern<ValueTuple<AccountsCache, Option<AccountProcess>>>
60+
new Pattern<(AccountsCache, Option<AccountProcess>)>
6161
{
6262
(LookupMsg m) => (cache, cache.Lookup(m.Id)),
6363

Exercises/Chapter05/Solutions.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@ static string DailyComment(DateTime day)
4949
return string.Join(" ", comments.ToArray());
5050
}
5151

52-
// note that here I use Tuple instead of KeyValuePair, but that's a minor detail
53-
static IEnumerable<ValueTuple<Predicate<T>, Func<T, R>>> Switch<T, R>()
54-
=> Enumerable.Empty<ValueTuple<Predicate<T>, Func<T, R>>>();
52+
// note that here I use a tuple instead of KeyValuePair, but that's a minor detail
53+
static IEnumerable<(Predicate<T>, Func<T, R>)> Switch<T, R>()
54+
=> Enumerable.Empty<(Predicate<T>, Func<T, R>)>();
5555

56-
static IEnumerable<ValueTuple<Predicate<T>, Func<T, R>>> Case<T, R>(
57-
this IEnumerable<ValueTuple<Predicate<T>, Func<T, R>>> rules
56+
static IEnumerable<(Predicate<T>, Func<T, R>)> Case<T, R>(
57+
this IEnumerable<(Predicate<T>, Func<T, R>)> rules
5858
, Predicate<T> pred, Func<T, R> func)
5959
=> rules.Append((pred, func));
6060

61-
static IEnumerable<R> MatchAll<T, R>(this IEnumerable<ValueTuple<Predicate<T>, Func<T, R>>> rules, T t)
61+
static IEnumerable<R> MatchAll<T, R>(this IEnumerable<(Predicate<T>, Func<T, R>)> rules, T t)
6262
=> rules.Where(rule => rule.Item1(t))
6363
.Map(rule => rule.Item2(t));
6464

@@ -75,12 +75,12 @@ public static string TestDateComment(string date)
7575
// method that returns the result of invoking the function of the _first_
7676
// matching case.
7777

78-
static IEnumerable<ValueTuple<Predicate<T>, Func<T, R>>> Case<T, R>(
79-
this IEnumerable<ValueTuple<Predicate<T>, Func<T, R>>> rules
78+
static IEnumerable<(Predicate<T>, Func<T, R>)> Case<T, R>(
79+
this IEnumerable<(Predicate<T>, Func<T, R>)> rules
8080
, T value, Func<T, R> func)
8181
=> rules.Append((new Predicate<T>(v => v.Equals(value)), func));
8282

83-
static R Match<T, R>(this IEnumerable<ValueTuple<Predicate<T>, Func<T, R>>> rules, T t)
83+
static R Match<T, R>(this IEnumerable<(Predicate<T>, Func<T, R>)> rules, T t)
8484
=> rules.Where(rule => rule.Item1(t))
8585
.First().Item2(t);
8686

LaYumba.Functional/Agent.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public static Agent<Msg> Start<State, Msg>
2828

2929
public static Agent<Msg, Reply> Start<State, Msg, Reply>
3030
(State initialState
31-
, Func<State, Msg, ValueTuple<State, Reply>> process)
31+
, Func<State, Msg, (State, Reply)> process)
3232
=> new TwoWayAgent<State, Msg, Reply>(initialState, process);
3333

3434
public static Agent<Msg, Reply> Start<State, Msg, Reply>
3535
(State initialState
36-
, Func<State, Msg, Task<ValueTuple<State, Reply>>> process)
36+
, Func<State, Msg, Task<(State, Reply)>> process)
3737
=> new TwoWayAgent<State, Msg, Reply>(initialState, process);
3838
}
3939

@@ -93,13 +93,13 @@ public StatefulAgent(State initialState
9393
class TwoWayAgent<State, Msg, Reply> : Agent<Msg, Reply>
9494
{
9595
private State state;
96-
private readonly ActionBlock<ValueTuple<Msg, TaskCompletionSource<Reply>>> actionBlock;
96+
private readonly ActionBlock<(Msg, TaskCompletionSource<Reply>)> actionBlock;
9797

98-
public TwoWayAgent(State initialState, Func<State, Msg, ValueTuple<State, Reply>> process)
98+
public TwoWayAgent(State initialState, Func<State, Msg, (State, Reply)> process)
9999
{
100100
state = initialState;
101101

102-
actionBlock = new ActionBlock<ValueTuple<Msg, TaskCompletionSource<Reply>>>(
102+
actionBlock = new ActionBlock<(Msg, TaskCompletionSource<Reply>)>(
103103
t =>
104104
{
105105
var result = process(state, t.Item1);
@@ -109,11 +109,11 @@ public TwoWayAgent(State initialState, Func<State, Msg, ValueTuple<State, Reply>
109109
}
110110

111111
// creates a 2-way agent with an async processing func
112-
public TwoWayAgent(State initialState, Func<State, Msg, Task<ValueTuple<State, Reply>>> process)
112+
public TwoWayAgent(State initialState, Func<State, Msg, Task<(State, Reply)>> process)
113113
{
114114
state = initialState;
115115

116-
actionBlock = new ActionBlock<ValueTuple<Msg, TaskCompletionSource<Reply>>>(
116+
actionBlock = new ActionBlock<(Msg, TaskCompletionSource<Reply>)>(
117117
async t => await process(state, t.Item1)
118118
.ContinueWith(task =>
119119
{

LaYumba.Functional/Pattern.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Pattern : Pattern<dynamic> { }
1414

1515
public class Pattern<R> : IEnumerable
1616
{
17-
IList<ValueTuple<Type, Func<object, R>>> funcs = new List<ValueTuple<Type, Func<object, R>>>();
17+
IList<(Type, Func<object, R>)> funcs = new List<(Type, Func<object, R>)>();
1818

1919
IEnumerator IEnumerable.GetEnumerator() => funcs.GetEnumerator();
2020

@@ -48,7 +48,7 @@ public R Match(object value)
4848
return matchingDel(value);
4949
}
5050

51-
static Func<ValueTuple<Type, Func<object, R>>, bool> InputArgMatchesTypeOf(object value)
51+
static Func<(Type, Func<object, R>), bool> InputArgMatchesTypeOf(object value)
5252
=> tup => tup.Item1.GetTypeInfo().IsAssignableFrom(value.GetType());
5353
}
5454
}

0 commit comments

Comments
 (0)