Mercurial > hg > Database > jungle-sharp
changeset 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 |
files | Main/jungle-main/store/transformer/PutAttribute.cs Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Main/jungle-main/util/DefaultEither.cs Main/jungle-main/util/Either.cs |
diffstat | 4 files changed, 18 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/Main/jungle-main/store/transformer/PutAttribute.cs Sat Jan 28 19:12:18 2017 +0900 +++ b/Main/jungle-main/store/transformer/PutAttribute.cs Tue Feb 07 20:50:50 2017 +0900 @@ -15,7 +15,6 @@ public PutAttribute(object _value) { key = _value.ToString(); - Debug.Log (key); value = _value; }
--- a/Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Sat Jan 28 19:12:18 2017 +0900 +++ b/Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Tue Feb 07 20:50:50 2017 +0900 @@ -31,7 +31,7 @@ - private Either<Error,JungleTreeEditor> _edit(NodePath _path, NodeEditor _e) + private Either<Error, JungleTreeEditor> _edit(NodePath _path, NodeEditor _e) { Either<Error, LoggingNode> either = editor.edit (root, _path, _e); if (either.isA ()) @@ -67,7 +67,7 @@ return _edit (_path, appendChildAt); } - public Either<Error,JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) { + public Either<Error, JungleTreeEditor> deleteChildAt(NodePath _path, int _pos) { DeleteChildAt deleteChildAt = new DeleteChildAt(_pos); return _edit(_path,deleteChildAt); } @@ -99,12 +99,12 @@ } public Either<Error,JungleTreeEditor> edit(NodePath _path, NodeEditor _editor) { - return _edit(_path,_editor); + return _edit(_path, _editor); } - public Either<Error,JungleTreeEditor> commit() { + public Either<Error, JungleTreeEditor> commit() { Either<Error,TransactionManager> either = this.txManager.commit(this.root, this.log); - if(either.isA()){ + if(either.isA()) { return DefaultEither<Error, JungleTreeEditor>.newA(either.a()); }
--- 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 ()); + } }
--- a/Main/jungle-main/util/Either.cs Sat Jan 28 19:12:18 2017 +0900 +++ b/Main/jungle-main/util/Either.cs Tue Feb 07 20:50:50 2017 +0900 @@ -4,5 +4,6 @@ bool isA(); B b(); bool isB(); - Either<A, B> fmap (System.Func<B, B> f, Either<A, B> e); + Either<A, B> fmap (System.Func<B, B> f); + Either<A, B> bind (System.Func<B, Either<A,B>> f); }