|
package implicits |
|
|
|
import java.io.File |
|
|
|
object ImplicitsDemo { |
|
|
|
trait Composite[T] { |
|
def value: T |
|
def isComposite: Boolean |
|
def children: List[Composite[T]] |
|
def descendants: List[Composite[T]] = |
|
children.map(child => child +: (if (child.isComposite) child.descendants else Nil)).flatten |
|
|
|
def print: Unit = print(0) |
|
|
|
def print(level: Int): Unit = { |
|
val indent = " " * level |
|
println(indent + "|_" + this) |
|
if (isComposite) children.foreach(_.print(level + 1)) |
|
} |
|
} |
|
|
|
implicit def fileToComposite(file: File): Composite[File] = new Composite[File] { |
|
def value: File = file |
|
override def isComposite = file.isDirectory() |
|
override def children: List[Composite[File]] = file.listFiles().toList.map(fileToComposite) |
|
override def toString = file.getName() |
|
} |
|
|
|
def main(args: Array[String]): Unit = { |
|
println("*********************printing descendants**************************************************") |
|
new File("C:/scala-2.10.2").descendants.foreach(composite => println(composite.value.getAbsolutePath())) |
|
println("*********************printing descendants as TREE ******************************************") |
|
new File("C:/scala-2.10.2").print |
|
} |
|
|
|
} |
|
|
|
/** |
|
*********************printing descendants************************************************** |
|
C:\scala-2.10.2\bin |
|
C:\scala-2.10.2\bin\fsc |
|
C:\scala-2.10.2\bin\fsc.bat |
|
C:\scala-2.10.2\bin\scala |
|
C:\scala-2.10.2\bin\scala.bat |
|
C:\scala-2.10.2\bin\scalac |
|
C:\scala-2.10.2\bin\scalac.bat |
|
C:\scala-2.10.2\bin\scaladoc |
|
C:\scala-2.10.2\bin\scaladoc.bat |
|
C:\scala-2.10.2\bin\scalap |
|
C:\scala-2.10.2\bin\scalap.bat |
|
C:\scala-2.10.2\doc |
|
C:\scala-2.10.2\doc\LICENSE |
|
C:\scala-2.10.2\doc\README |
|
C:\scala-2.10.2\doc\tools |
|
C:\scala-2.10.2\doc\tools\css |
|
C:\scala-2.10.2\doc\tools\css\style.css |
|
C:\scala-2.10.2\doc\tools\fsc.html |
|
C:\scala-2.10.2\doc\tools\images |
|
C:\scala-2.10.2\doc\tools\images\external.gif |
|
C:\scala-2.10.2\doc\tools\images\scala_logo.png |
|
C:\scala-2.10.2\doc\tools\index.html |
|
C:\scala-2.10.2\doc\tools\scala.html |
|
C:\scala-2.10.2\doc\tools\scalac.html |
|
C:\scala-2.10.2\doc\tools\scaladoc.html |
|
C:\scala-2.10.2\doc\tools\scalap.html |
|
C:\scala-2.10.2\examples |
|
C:\scala-2.10.2\examples\actors |
|
C:\scala-2.10.2\examples\actors\auction.scala |
|
C:\scala-2.10.2\examples\actors\boundedbuffer.scala |
|
C:\scala-2.10.2\examples\actors\channels.scala |
|
C:\scala-2.10.2\examples\actors\fringe.scala |
|
C:\scala-2.10.2\examples\actors\links.scala |
|
C:\scala-2.10.2\examples\actors\looping.scala |
|
C:\scala-2.10.2\examples\actors\message.scala |
|
C:\scala-2.10.2\examples\actors\pingpong.scala |
|
C:\scala-2.10.2\examples\actors\producers.scala |
|
C:\scala-2.10.2\examples\actors\seq.scala |
|
C:\scala-2.10.2\examples\boundedbuffer.scala |
|
C:\scala-2.10.2\examples\computeserver.scala |
|
C:\scala-2.10.2\examples\fors.scala |
|
C:\scala-2.10.2\examples\futures.scala |
|
C:\scala-2.10.2\examples\gadts.scala |
|
C:\scala-2.10.2\examples\iterators.scala |
|
C:\scala-2.10.2\examples\maps.scala |
|
C:\scala-2.10.2\examples\monads |
|
C:\scala-2.10.2\examples\monads\callccInterpreter.scala |
|
C:\scala-2.10.2\examples\monads\directInterpreter.scala |
|
C:\scala-2.10.2\examples\monads\errorInterpreter.scala |
|
C:\scala-2.10.2\examples\monads\simpleInterpreter.scala |
|
C:\scala-2.10.2\examples\monads\stateInterpreter.scala |
|
C:\scala-2.10.2\examples\oneplacebuffer.scala |
|
C:\scala-2.10.2\examples\package.scala |
|
C:\scala-2.10.2\examples\parsing |
|
C:\scala-2.10.2\examples\parsing\ArithmeticParser.scala |
|
C:\scala-2.10.2\examples\parsing\ArithmeticParsers.scala |
|
C:\scala-2.10.2\examples\parsing\JSON.scala |
|
C:\scala-2.10.2\examples\parsing\lambda |
|
C:\scala-2.10.2\examples\parsing\lambda\Main.scala |
|
C:\scala-2.10.2\examples\parsing\lambda\test |
|
C:\scala-2.10.2\examples\parsing\lambda\test\test-01.kwi |
|
C:\scala-2.10.2\examples\parsing\lambda\test\test-02.kwi |
|
C:\scala-2.10.2\examples\parsing\lambda\test\test-03.kwi |
|
C:\scala-2.10.2\examples\parsing\lambda\test\test-04.kwi |
|
C:\scala-2.10.2\examples\parsing\lambda\test\test-05.kwi |
|
C:\scala-2.10.2\examples\parsing\lambda\test\test-06.kwi |
|
C:\scala-2.10.2\examples\parsing\lambda\test\test-07.kwi |
|
C:\scala-2.10.2\examples\parsing\lambda\test\test-08.kwi |
|
C:\scala-2.10.2\examples\parsing\lambda\TestParser.scala |
|
C:\scala-2.10.2\examples\parsing\lambda\TestSyntax.scala |
|
C:\scala-2.10.2\examples\parsing\ListParser.scala |
|
C:\scala-2.10.2\examples\parsing\ListParsers.scala |
|
C:\scala-2.10.2\examples\parsing\MiniML.scala |
|
C:\scala-2.10.2\examples\patterns.scala |
|
C:\scala-2.10.2\examples\sort.scala |
|
C:\scala-2.10.2\examples\sort1.scala |
|
C:\scala-2.10.2\examples\sort2.scala |
|
C:\scala-2.10.2\examples\tcpoly |
|
C:\scala-2.10.2\examples\tcpoly\monads |
|
C:\scala-2.10.2\examples\tcpoly\monads\Monads.scala |
|
C:\scala-2.10.2\examples\xml |
|
C:\scala-2.10.2\examples\xml\phonebook |
|
C:\scala-2.10.2\examples\xml\phonebook\embeddedBook.scala |
|
C:\scala-2.10.2\examples\xml\phonebook\phonebook.scala |
|
C:\scala-2.10.2\examples\xml\phonebook\phonebook1.scala |
|
C:\scala-2.10.2\examples\xml\phonebook\phonebook2.scala |
|
C:\scala-2.10.2\examples\xml\phonebook\phonebook3.scala |
|
C:\scala-2.10.2\examples\xml\phonebook\verboseBook.scala |
|
C:\scala-2.10.2\lib |
|
C:\scala-2.10.2\lib\akka-actors.jar |
|
C:\scala-2.10.2\lib\diffutils.jar |
|
C:\scala-2.10.2\lib\jline.jar |
|
C:\scala-2.10.2\lib\scala-actors-migration.jar |
|
C:\scala-2.10.2\lib\scala-actors.jar |
|
C:\scala-2.10.2\lib\scala-compiler.jar |
|
C:\scala-2.10.2\lib\scala-library.jar |
|
C:\scala-2.10.2\lib\scala-partest.jar |
|
C:\scala-2.10.2\lib\scala-reflect.jar |
|
C:\scala-2.10.2\lib\scala-swing.jar |
|
C:\scala-2.10.2\lib\scalap.jar |
|
C:\scala-2.10.2\lib\typesafe-config.jar |
|
C:\scala-2.10.2\man |
|
C:\scala-2.10.2\man\man1 |
|
C:\scala-2.10.2\man\man1\fsc.1 |
|
C:\scala-2.10.2\man\man1\scala.1 |
|
C:\scala-2.10.2\man\man1\scalac.1 |
|
C:\scala-2.10.2\man\man1\scaladoc.1 |
|
C:\scala-2.10.2\man\man1\scalap.1 |
|
C:\scala-2.10.2\misc |
|
C:\scala-2.10.2\misc\scala-devel |
|
C:\scala-2.10.2\misc\scala-devel\plugins |
|
C:\scala-2.10.2\misc\scala-devel\plugins\continuations.jar |
|
C:\scala-2.10.2\src |
|
C:\scala-2.10.2\src\fjbg-src.jar |
|
C:\scala-2.10.2\src\msil-src.jar |
|
C:\scala-2.10.2\src\scala-actors-src.jar |
|
C:\scala-2.10.2\src\scala-compiler-src.jar |
|
C:\scala-2.10.2\src\scala-library-src.jar |
|
C:\scala-2.10.2\src\scala-partest-src.jar |
|
C:\scala-2.10.2\src\scala-reflect-src.jar |
|
C:\scala-2.10.2\src\scala-swing-src.jar |
|
C:\scala-2.10.2\src\scalap-src.jar |
|
********************* printing file as TREE ****************************************** |
|
|_scala-2.10.2 |
|
|_bin |
|
|_fsc |
|
|_fsc.bat |
|
|_scala |
|
|_scala.bat |
|
|_scalac |
|
|_scalac.bat |
|
|_scaladoc |
|
|_scaladoc.bat |
|
|_scalap |
|
|_scalap.bat |
|
|_doc |
|
|_LICENSE |
|
|_README |
|
|_tools |
|
|_css |
|
|_style.css |
|
|_fsc.html |
|
|_images |
|
|_external.gif |
|
|_scala_logo.png |
|
|_index.html |
|
|_scala.html |
|
|_scalac.html |
|
|_scaladoc.html |
|
|_scalap.html |
|
|_examples |
|
|_actors |
|
|_auction.scala |
|
|_boundedbuffer.scala |
|
|_channels.scala |
|
|_fringe.scala |
|
|_links.scala |
|
|_looping.scala |
|
|_message.scala |
|
|_pingpong.scala |
|
|_producers.scala |
|
|_seq.scala |
|
|_boundedbuffer.scala |
|
|_computeserver.scala |
|
|_fors.scala |
|
|_futures.scala |
|
|_gadts.scala |
|
|_iterators.scala |
|
|_maps.scala |
|
|_monads |
|
|_callccInterpreter.scala |
|
|_directInterpreter.scala |
|
|_errorInterpreter.scala |
|
|_simpleInterpreter.scala |
|
|_stateInterpreter.scala |
|
|_oneplacebuffer.scala |
|
|_package.scala |
|
|_parsing |
|
|_ArithmeticParser.scala |
|
|_ArithmeticParsers.scala |
|
|_JSON.scala |
|
|_lambda |
|
|_Main.scala |
|
|_test |
|
|_test-01.kwi |
|
|_test-02.kwi |
|
|_test-03.kwi |
|
|_test-04.kwi |
|
|_test-05.kwi |
|
|_test-06.kwi |
|
|_test-07.kwi |
|
|_test-08.kwi |
|
|_TestParser.scala |
|
|_TestSyntax.scala |
|
|_ListParser.scala |
|
|_ListParsers.scala |
|
|_MiniML.scala |
|
|_patterns.scala |
|
|_sort.scala |
|
|_sort1.scala |
|
|_sort2.scala |
|
|_tcpoly |
|
|_monads |
|
|_Monads.scala |
|
|_xml |
|
|_phonebook |
|
|_embeddedBook.scala |
|
|_phonebook.scala |
|
|_phonebook1.scala |
|
|_phonebook2.scala |
|
|_phonebook3.scala |
|
|_verboseBook.scala |
|
|_lib |
|
|_akka-actors.jar |
|
|_diffutils.jar |
|
|_jline.jar |
|
|_scala-actors-migration.jar |
|
|_scala-actors.jar |
|
|_scala-compiler.jar |
|
|_scala-library.jar |
|
|_scala-partest.jar |
|
|_scala-reflect.jar |
|
|_scala-swing.jar |
|
|_scalap.jar |
|
|_typesafe-config.jar |
|
|_man |
|
|_man1 |
|
|_fsc.1 |
|
|_scala.1 |
|
|_scalac.1 |
|
|_scaladoc.1 |
|
|_scalap.1 |
|
|_misc |
|
|_scala-devel |
|
|_plugins |
|
|_continuations.jar |
|
|_src |
|
|_fjbg-src.jar |
|
|_msil-src.jar |
|
|_scala-actors-src.jar |
|
|_scala-compiler-src.jar |
|
|_scala-library-src.jar |
|
|_scala-partest-src.jar |
|
|_scala-reflect-src.jar |
|
|_scala-swing-src.jar |
|
|_scalap-src.jar |
|
**/ |