Mercurial > hg > Database > jungle-sharp
comparison Main/jungle-main/util/DefaultEither.cs @ 33:56de71ae6f7e
Implementation of fmap.
author | Kazuma Takeda |
---|---|
date | Sat, 28 Jan 2017 19:12:18 +0900 |
parents | 1f99e150f336 |
children | a79781723862 |
comparison
equal
deleted
inserted
replaced
32:07318c10b894 | 33:56de71ae6f7e |
---|---|
1 | 1 |
2 public class DefaultEither<A,B> : Either<A,B> { | 2 public class DefaultEither<A,B> : Either<A,B> { |
3 private A theA; | 3 private A theA; |
4 private B theB; | 4 private B theB; |
5 | 5 |
6 private DefaultEither(A _theA, B _theB){ | 6 public void SetB (B b) { |
7 this.theB = b; | |
8 } | |
9 | |
10 public void SetA (A a) { | |
11 this.theA = a; | |
12 } | |
13 | |
14 public delegate B Func (B b); | |
15 | |
16 public DefaultEither(A _theA, B _theB){ | |
7 theA = _theA; | 17 theA = _theA; |
8 theB = _theB; | 18 theB = _theB; |
9 } | 19 } |
10 | 20 |
11 public static DefaultEither<A,B> newA(A _theA) | 21 public static DefaultEither<A,B> newA(A _theA) |
39 public bool isB() | 49 public bool isB() |
40 { | 50 { |
41 return theB != null; | 51 return theB != null; |
42 } | 52 } |
43 | 53 |
54 public Either<A, B> fmap(System.Func<B, B> f, Either<A,B> e) { | |
55 if (e.isA ()) { | |
56 return e; | |
57 } | |
58 this.SetB (f (e.b())); | |
59 return this; | |
60 } | |
61 | |
44 } | 62 } |