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
//-------------------------------------// | |
// readFile is a high order function // | |
// which can take another function // | |
// as parameter // | |
//-------------------------------------// | |
def using[T](f: File)(handler: FileInputStream => T): T = { | |
val resource = new java.io.FileInputStream(f) | |
try { | |
handler(resource) |
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
//-------------------------------------------// | |
// function as parameter java implementation // | |
//-------------------------------------------// | |
class UerFetcher implement Callable<User> { | |
private String userId; | |
@Autowired | |
private UserService userService; | |
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
val fa = callToRemoteServiceA(); | |
val fb = callToRemoteServiceB(); | |
val fc = callToRemoteServiceC(fa.get()); | |
val fd = callToRemoteServiceD(fb.get()); | |
val fe = callToRemoteServiceE(fb.get()); | |
val executor = new ThreadPoolExecutor(4, 4, 1, TimeUnit.MINUTES, new LinkedBlockingQueue[Runnable]()) |
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
def solveRPN(expression: String):String = { | |
expression.split(" ").foldLeft(List[String]()) { | |
(stack:List[String], e:String) => | |
e match { | |
case "*" => | |
stack match { | |
case List(z) => List(z) | |
case x :: y :: ys => (y.toInt * x.toInt).toString :: ys | |
} | |
case "+" => |
NewerOlder