Advertisement
Guest User

Untitled

a guest
Oct 9th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.77 KB | None | 0 0
  1. package com.oglabs.scala_sbt_test.lab_01
  2.  
  3. /**
  4.  * Created by Oskar Gargas on 09.10.14.
  5.  */
  6. class Zad_01 {
  7.   println("--- Zadanie 1 ---")
  8.  
  9.   private val dniTygodnia = List("poniedziałek", "wtorek", "środa", "czwartek", "piątek", "sobota", "niedziela")
  10.  
  11.   def podpunktA(): Unit = {
  12.     println("--- Podpunkt A ---")
  13.     for(d <- dniTygodnia) println(d)
  14.   }
  15.  
  16.   def podpunktB(): Unit = {
  17.     println("--- Podpunkt B ---")
  18.     for(d <- dniTygodnia.filter(d => d.startsWith("p"))) println(d)
  19.   }
  20.  
  21.   def podpunktC(): Unit = {
  22.     println("--- Podpunkt C ---")
  23.     dniTygodnia.foreach(d => println(d))
  24.   }
  25.  
  26.   def podpunktD(): Unit = {
  27.     println("--- Podpunkt D ---")
  28.     var i = 0
  29.     while(i < dniTygodnia.length) {
  30.       println(dniTygodnia(i))
  31.       i = i + 1
  32.     }
  33.   }
  34.  
  35.   def podpunktE(): Unit = {
  36.     println("--- Podpunkt E ---")
  37.  
  38.     def rekurencyjnie(lista: List[String]): Unit = {
  39.       if (lista.nonEmpty) {
  40.         println(lista.head)
  41.         rekurencyjnie(lista.tail)
  42.       }
  43.     }
  44.  
  45.     rekurencyjnie(dniTygodnia)
  46.   }
  47.  
  48.   def podpunktF(): Unit = {
  49.     println("--- Podpunkt F ---")
  50.  
  51.     def rekurencyjnie(lista: List[String]): Unit = {
  52.       if (lista.nonEmpty) {
  53.         println(lista.last)
  54.         rekurencyjnie(lista.init)
  55.       }
  56.     }
  57.  
  58.     rekurencyjnie(dniTygodnia)
  59.   }
  60.  
  61.   def podpunktG(): Unit = {
  62.     println("--- Podpunkt F ---")
  63.     val foldL = dniTygodnia.foldLeft("")((b, a) => b + a + '\n')
  64.     val foldR = dniTygodnia.foldRight("")((a, b) => a + '\n' + b)
  65.     print("-- foldLeft\n" + foldL)
  66.     print("-- foldRight\n" + foldR)
  67.   }
  68.  
  69.   def podpunktH(): Unit = {
  70.     println("--- Podpunkt H ---")
  71.     val foldL = dniTygodnia.filter(d => d.startsWith("p")).foldLeft("")((b, a) => b + a + '\n')
  72.     print(foldL)
  73.   }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement