#zadanie1 Stworz klase Person(name: String, gender: String). Utworz liste z ludzimi, np.
Beyonce (f)
David Bowie (m)
Elvis Costello (m)
val dataStream = data.map { new MapFunction[A, B] { | |
val client = new NonBlockingStatsDClient(null, "localhost", 8125) | |
override def map(a: A): [A, B] = { | |
client.increment("A processing") | |
a.toB | |
} | |
} | |
} |
set nocompatible " be iMproved, required | |
filetype off " required | |
set autoindent | |
set number | |
" set the runtime path to include Vundle and initialize | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
au FileType haskell nnoremap <buffer> <F1> :HdevtoolsType<CR> | |
au FileType haskell nnoremap <buffer> <silent> <F2> :HdevtoolsClear<CR> | |
au FileType haskell nnoremap <buffer> <silent> <F3> :HdevtoolsInfo<CR> |
#zadanie1 Stworz klase Person(name: String, gender: String). Utworz liste z ludzimi, np.
Beyonce (f)
David Bowie (m)
Elvis Costello (m)
W ramach przypomnienia Scali, trzeba przejrzec podstawy
https://gist.github.com/fijolekProjects/4361b255806fb4f9f999
pozniej zrobic proste cwiczenia (bez ostatniego) https://gist.github.com/fijolekProjects/acd7bbf7ec14d58b2c1b
przypomniec sobie programowanie obiektowe https://gist.github.com/fijolekProjects/e4fefcbe21dca76110cc
Scala jest jezykiem statycznie kompilowanym tzn, ze program musi najpierw skompilowac sie zeby moc dac sie uruchomic. W czasie kompilacji kompilator szuka bledow w kodzie. Jesli taki znajdzie nie mozna uruchomic programu i jestesmy zmuszeni do poprawienia takiego bledu.
val age: Int = "Jack" //nie skompiluje sie bo zadeklarowalismy typ zmiennej jako liczba a przypisalismy stringa
//nazywamy to bledem kompilacji
scala> import scalaz._ | |
import scalaz._ | |
scala> import Scalaz._ | |
import Scalaz._ | |
scala> "occurrence".sliding(2).toList.map { pair => Map(pair(0) -> pair(1).toString) }.foldMap(identity) | |
res0: scala.collection.immutable.Map[String,String] = Map(e -> n, n -> c, u -> r, c -> cue, r -> re, o -> c) | |
scala> res0.mapValues(_.groupBy(identity).mapValues(_.size)) |
1.1. Napisz funkcje, ktora przesuwa wiersz w prawo.
def shiftRight(row: List[Int]): List[Int]
Przypadki testowe:
object P13 { | |
val list = List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e) | |
//> list : List[Symbol] = List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, ' | |
//| e, 'e) | |
def encodeDirect1[A](xs: List[A]): List[(Int, A)] = xs.span(_ == xs.head) match { | |
case (Nil, Nil) => Nil | |
case (one, rest) => (one.length, one.head) :: encodeDirect1(rest) | |
} //> encodeDirect1: [A](xs: List[A])List[(Int, A)] | |
encodeDirect1(list) //> res0: List[(Int, Symbol)] = List((4,'a), (1,'b), (2,'c), (2,'a), (1,'d), (4, |
object P12 { | |
val list = List((4, 'a), (1, 'b), (2, 'c), (2, 'a), (1, 'd), (4, 'e)) | |
//> list : List[(Int, Symbol)] = List((4,'a), (1,'b), (2,'c), (2,'a), (1,'d), (4 | |
//| ,' | |
def decode4[A](xs: List[(Int, A)]): List[A] = { | |
for (one <- xs; howMany <- 1 to one._1) yield one._2 | |
} //> decode4: [A](xs: List[(Int, A)])List[A] | |
decode4(list) //> res3: List[Symbol] = List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, ' | |
//| e, 'e) |
scala> (1 to 5) map ("*" * _) foreach (println) | |
* | |
** | |
*** | |
**** | |
***** |