Created
May 19, 2014 14:51
-
-
Save nicholasren/1b079bf7610b41abb674 to your computer and use it in GitHub Desktop.
scala the language matters training
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; | |
publiv User call() { | |
return userService.get(userId); | |
} | |
} | |
List<String> userIds = null;// List( "1001", "1003", "1005") | |
List<Future<User>> users = new ArrayList<Future<User>>() | |
for(id : userIds) { | |
users.add(executor.submit(new UserFetcher(id))) | |
} |
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 in scala // | |
//-------------------------------------------// | |
val userIds = List("1001", "1002", "1003", "1004") | |
val userFetcher: String => Future[User] = (id: String) => future { UserService.get(id) } | |
val users: List[Future[User]] = userIds.map(userFetcher) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment