Created
October 25, 2017 23:26
-
-
Save AlvarezAriel/1580118f99d022caa9ef220dd87e3d9b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package ar.edu.unq.obj3.ejercicio | |
| trait ConNombre { | |
| def nombre:String | |
| } | |
| case class Humano(nombre:String, altura:Int) | |
| extends ConNombre | |
| case class SuperHeroe(identidad:ConNombre, disfraz: Disfraz) | |
| object SuperHeroe { | |
| def crearDisfraz()(normal:Humano):Disfraz = | |
| Disfraz(normal.altura) | |
| def vestir(conNombre: ConNombre)(disfraz: Disfraz) = | |
| new SuperHeroe(conNombre,disfraz) | |
| } | |
| object Pipe { | |
| implicit class ImplicitPipe[T](val o:T) { | |
| def |>[R](transform:(T)=> R ) : R = transform(o) | |
| } | |
| } | |
| case class Disfraz(largo:Int) | |
| object Main extends App { | |
| import SuperHeroe._ | |
| import Pipe.ImplicitPipe | |
| private val humano = Humano("Pepe", 160) | |
| val posta = new ImplicitPipe(humano).|>(crearDisfraz()) | |
| val superHeroe = humano |> crearDisfraz() |> vestir(humano) | |
| println(superHeroe) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment