3737import tlc2 .util .Context ;
3838import tlc2 .value .IValue ;
3939import tlc2 .value .Values ;
40- import tlc2 .value .impl .Applicable ;
4140import tlc2 .value .impl .BoolValue ;
42- import tlc2 .value .impl .Enumerable ;
4341import tlc2 .value .impl .OpValue ;
4442import tlc2 .value .impl .SetEnumValue ;
4543import tlc2 .value .impl .StringValue ;
4644import tlc2 .value .impl .TupleValue ;
4745import tlc2 .value .impl .Value ;
48- import tlc2 .value .impl .ValueEnumeration ;
4946import tlc2 .value .impl .ValueVec ;
5047
5148public final class SequencesExt {
@@ -97,29 +94,6 @@ public String longestCommonPrefix(String[] strs) {
9794 }
9895 return prefix ;
9996 }
100- /*
101- */
102- @ TLAPlusOperator (identifier = "FoldFunction" , module = "Functions" , warn = false )
103- public static Value foldFunction (final OpValue op , final Value base , final Applicable fun ) {
104- return foldFunctionOnSet (op , base , fun , (Enumerable ) fun .getDomain ());
105- }
106-
107- @ TLAPlusOperator (identifier = "FoldFunctionOnSet" , module = "Functions" , warn = false )
108- public static Value foldFunctionOnSet (final OpValue op , final Value base , final Applicable fun , final Enumerable subdomain ) {
109-
110- final Value [] args = new Value [2 ];
111- args [1 ] = base ;
112-
113- final ValueEnumeration ve = subdomain .elements ();
114-
115- Value v = null ;
116- while ((v = ve .nextElement ()) != null ) {
117- args [0 ] = fun .select (v );
118- args [1 ] = op .apply (args , EvalControl .Clear );
119- }
120-
121- return args [1 ];
122- }
12397
12498 @ TLAPlusOperator (identifier = "LongestCommonPrefix" , module = "SequencesExt" , warn = false )
12599 public static Value longestCommonPrefix (final Value val ) {
@@ -195,7 +169,7 @@ private static Value longestCommonPrefix(final StringValue first, final ValueVec
195169
196170 @ TLAPlusOperator (identifier = "FoldSeq" , module = "SequencesExt" , warn = false )
197171 public static Value foldSeq (final OpValue op , final Value base , final TupleValue tv ) {
198- return foldLeft (op , base , tv );
172+ return Functions . foldFunction (op , base , tv );
199173 }
200174
201175 @ TLAPlusOperator (identifier = "FoldLeft" , module = "SequencesExt" , warn = false )
@@ -207,6 +181,7 @@ public static Value foldLeft(final OpValue op, final Value base, final Value val
207181 new String [] { "FoldLeft" , "sequence" , Values .ppr (val .toString ()) });
208182 }
209183
184+ // FoldLeft base is left (first) operand.
210185 final Value [] args = new Value [2 ];
211186 args [0 ] = base ;
212187
@@ -228,6 +203,7 @@ public static Value foldRight(final OpValue op, final Value val, final Value bas
228203 new String [] { "FoldRight" , "sequence" , Values .ppr (val .toString ()) });
229204 }
230205
206+ // FoldRight base is right (second) operand.
231207 final Value [] args = new Value [2 ];
232208 args [1 ] = base ;
233209
0 commit comments