def transform = Action {
val fileStream: Enumerator[Array[Byte]] = {
Enumerator.fromFile(new File("data.txt"))
}
val transfo = Enumeratee.map[Array[Byte]]{byteArray => | //val xmlNode = xml.XML.loadFile("xxx") | |
| val xmlNode = | |
| <persons> | |
| <person age="30"> | |
| <name>bob</name> | |
| </person> | |
| <person age="40"> | |
| <name>joe</name> | |
| </person> |
| import java.util.Arrays; | |
| public class Lambda { | |
| public static void main (String[] args){ | |
| Arrays.asList("aaa", "bbb", "ccc", "abb").stream() | |
| .filter((String w) -> w.startsWith("a")) | |
| .forEach(w -> System.out.println(w)); | |
| } | |
| } |
"For comprehension" is a another syntaxe to use map, flatMap and withFilter (or filter) methods.
yield keyword is used to aggregate values in the resulting structure.
This composition can be used on any type implementing this methods, like List, Option, Try, Future...
#Play2 : Les Iteratees expliqués aux humains... francophones!
Disclaimer : Ce qui suit est la traduction d'un article anglophone paru sur le blog mandubian.com
Vous pouvez retrouver l'article original ici
Vous avez probablement remarqué une nouvelle fonctionnalité intrigante de Play2 nommée Iteratee (ainsi que ses compagnons Enumerators et Enumeratee).
Le but de cet article est d'essayer de rendre le concept d'Iteratee compréhensible pour le plus grand nombre avec des arguments simples, en évitant l'approche mathématique / fonctionnelle.
Cet article ne prétend pas tout expliquer à propos des Iteratee / Enumerator / Enumeratee mais traite plutôt les idées qui se cachent derrière.
##MixedTweets
We will see how to mix 2 twitter searches and push the results to the browser in real time.
First, checkout this mini project
To try it, you need to install Play 2.0
###Controller