Commits

Sergei Vavinov committed cb11695

asFunction methods

Comments (0)

Files changed (3)

src/main/java/ru/yandex/bolts/function/Function1I.java

 package ru.yandex.bolts.function;
 
-
 /**
  * @author Stepan Koltsov
  */
 public abstract class Function1I<A> implements java.lang.Comparable<A>  {
     public abstract int apply(A a);
 
+    public Function<A, Integer> asFunction() {
+        return new Function<A, Integer>() {
+            public Integer apply(A a) {
+                return Function1I.this.apply(a);
+            }
+
+            @Override
+            public String toString() {
+                return Function1I.this.toString();
+            }
+        };
+    }
+    
     @Override
     public int compareTo(A o) {
         return apply(o);

src/main/java/ru/yandex/bolts/function/Function2B.java

         return Function2B.<A, B>bind2F2().bind1(this);
     }
 
-    public Function1B<Tuple2<A, B>> asTupleFunction() {
-        return new Function1B<Tuple2<A, B>>() {
-            public boolean apply(Tuple2<A, B> a) {
+    public Function<Tuple2<A, B>, Boolean> asFunction() {
+        return new Function<Tuple2<A, B>, Boolean>() {
+            public Boolean apply(Tuple2<A, B> a) {
                 return Function2B.this.apply(a.get1(), a.get2());
             }
         };

src/main/java/ru/yandex/bolts/function/Function2I.java

 package ru.yandex.bolts.function;
 
+import ru.yandex.bolts.collection.Tuple2;
 
 
 /**
         };
     }
 
+    public Function<Tuple2<A, B>, Integer> asFunction() {
+        return new Function<Tuple2<A, B>, Integer>() {
+            public Integer apply(Tuple2<A, B> a) {
+                return Function2I.this.apply(a.get1(), a.get2());
+            }
+        };
+    }
+
+
     /** Invert current comparator */
     public Function2I<B, A> invert() {
         return new Function2I<B, A>() {