Last active
August 29, 2015 14:07
-
-
Save Gab-km/f9d2578fd56c65e1ebbc to your computer and use it in GitHub Desktop.
カリー化とインターフェイス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TVar -> TResult | |
interface Applyable<TVar, TResult> { | |
public abstract TResult apply(TVar variable); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program { | |
public static void main(String[] args) { | |
// 一旦別の関数的なものに受けて、部品チックに | |
Applyable<String, Boolean> find_s = (new StringFinder()).apply("s"); | |
System.out.println(find_s.apply("sunotora")); //=> true | |
System.out.println(find_s.apply("gab_km")); //=> false | |
// 即時に適用 | |
System.out.println((new StringFinder()).apply("m").apply("sunotora")); //=> false | |
System.out.println((new StringFinder()).apply("m").apply("gab_km")); //=> true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// String -> String -> Boolean | |
class StringFinder implements Applyable<String, Applyable<String, Boolean>> { | |
@Override | |
public Applyable<String, Boolean> apply(String target) { | |
final String variable = target; | |
// String -> Boolean | |
return new Applyable<String, Boolean>() { | |
public Boolean apply(String value) { | |
return value.contains(variable); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment