click below
click below
Normal Size Small Size show me how
Scala
Funções Anonimas e Currying
| Term | Definition |
|---|---|
| Estrutura básica de uma função anonima. | (arg1 : ArgType, arg2 : ArgType, ... , argN : ArgType) => Corpo da função |
| Dada uma lista a Função deve encontrar múltiplos usando currying. | def filter(xs: List[Int], p: Int => Boolean): List[Int] = if (xs.isEmpty) xs else if (p(xs.head)) xs.head :: filter(xs.tail, p) else filter(xs.tail, p) def modN(n: Int)(x: Int) = ((x % n) == 0) |
| Enviar uma mensagem de uma classe para outra usando currying | def route(m:Message)(e:Endpoint) = { e.send(m) } |