# HG changeset patch # User Kazuma Takeda # Date 1485598338 -32400 # Node ID 56de71ae6f7e13866f324b9990331e16346b58b3 # Parent 07318c10b894f8b01b87f735f7e4cf4dc7de41a4 Implementation of fmap. diff -r 07318c10b894 -r 56de71ae6f7e Main/jungle-main/JungleTreeEditor.cs --- a/Main/jungle-main/JungleTreeEditor.cs Fri Jan 20 07:43:43 2017 +0900 +++ b/Main/jungle-main/JungleTreeEditor.cs Sat Jan 28 19:12:18 2017 +0900 @@ -5,6 +5,7 @@ Either addNewChildAt(NodePath path,int pos); Either deleteChildAt(NodePath path,int pos); Either putAttribute(NodePath path, string key, object value); + Either putAttribute(NodePath path, object value); Either putAttribute(string key, object value); Either putAttribute(object value); // add Method put Attribute (path, T?); diff -r 07318c10b894 -r 56de71ae6f7e Main/jungle-main/transaction/DefaultJungleTreeEditor.cs --- a/Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Fri Jan 20 07:43:43 2017 +0900 +++ b/Main/jungle-main/transaction/DefaultJungleTreeEditor.cs Sat Jan 28 19:12:18 2017 +0900 @@ -50,6 +50,7 @@ JungleTreeEditor newEditor = new DefaultJungleTreeEditor (newNode, txManager, editor, newTreeOpLog); newEditor.SetPrevPath (this.prevPath); + return DefaultEither.newB (newEditor); } @@ -77,6 +78,11 @@ return _edit (_path, putAttribute); } + public Either putAttribute(NodePath _path, object _value) { + PutAttribute putAttribute = new PutAttribute (_value.ToString(), _value); + return _edit (_path, putAttribute); + } + public Either putAttribute(string _key, object _value) { PutAttribute putAttribute = new PutAttribute (_key, _value); return _edit (prevPath, putAttribute); diff -r 07318c10b894 -r 56de71ae6f7e Main/jungle-main/util/DefaultEither.cs --- 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 fmap(System.Func f, Either e) { + if (e.isA ()) { + return e; + } + this.SetB (f (e.b())); + return this; + } + } diff -r 07318c10b894 -r 56de71ae6f7e Main/jungle-main/util/Either.cs --- a/Main/jungle-main/util/Either.cs Fri Jan 20 07:43:43 2017 +0900 +++ b/Main/jungle-main/util/Either.cs Sat Jan 28 19:12:18 2017 +0900 @@ -1,7 +1,8 @@  -public interface Either { +public interface Either { A a(); bool isA(); B b(); bool isB(); + Either fmap (System.Func f, Either e); } diff -r 07318c10b894 -r 56de71ae6f7e Main/jungle-network/transaction/NetworkDefaultJungleTreeEditor.cs --- a/Main/jungle-network/transaction/NetworkDefaultJungleTreeEditor.cs Fri Jan 20 07:43:43 2017 +0900 +++ b/Main/jungle-network/transaction/NetworkDefaultJungleTreeEditor.cs Sat Jan 28 19:12:18 2017 +0900 @@ -103,6 +103,12 @@ return this.TreeEditor(_path, putAttribute); } + public Either putAttribute(NodePath _path, object _value) + { + PutAttribute putAttribute = new PutAttribute(_value.ToString(), _value); + return this.TreeEditor(_path, putAttribute); + } + public Either putAttribute(string _key, object _value) { PutAttribute putAttribute = new PutAttribute(_key, _value);