Mercurial > hg > Database > jungle-sharp
diff 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 |
line wrap: on
line diff
--- a/Main/jungle-main/util/DefaultEither.cs Fri Jan 20 07:43:43 2017 +0900 +++ b/Main/jungle-main/util/DefaultEither.cs Sat Jan 28 19:12:18 2017 +0900 @@ -3,7 +3,17 @@ private A theA; private B theB; - private DefaultEither(A _theA, B _theB){ + public void SetB (B b) { + this.theB = b; + } + + public void SetA (A a) { + this.theA = a; + } + + public delegate B Func (B b); + + public DefaultEither(A _theA, B _theB){ theA = _theA; theB = _theB; } @@ -41,4 +51,12 @@ return theB != null; } + public Either<A, B> fmap(System.Func<B, B> f, Either<A,B> e) { + if (e.isA ()) { + return e; + } + this.SetB (f (e.b())); + return this; + } + }