Mercurial > hg > Database > jungle-sharp
diff Main/jungle-main/util/DefaultEither.cs @ 34:a79781723862
Add bind function to Either.cs
Rewrite use bind.
author | Kazuma Takeda |
---|---|
date | Tue, 07 Feb 2017 20:50:50 +0900 |
parents | 56de71ae6f7e |
children | f2ea780b3e80 |
line wrap: on
line diff
--- a/Main/jungle-main/util/DefaultEither.cs Sat Jan 28 19:12:18 2017 +0900 +++ b/Main/jungle-main/util/DefaultEither.cs Tue Feb 07 20:50:50 2017 +0900 @@ -3,16 +3,6 @@ private A theA; private 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; @@ -51,12 +41,18 @@ return theB != null; } - public Either<A, B> fmap(System.Func<B, B> f, Either<A,B> e) { - if (e.isA ()) { - return e; + public Either<A, B> fmap(System.Func<B, B> f) { + if (isA ()) { + return this; } - this.SetB (f (e.b())); - return this; + return newB(f(b())); } + public Either<A, B> bind (System.Func<B, Either<A, B>> f) { + if (isA ()) { + return this; + } + + return f (b ()); + } }