My Scala program won't print anything -


basically i'm trying write program has list of books , authors , prints 2 things out, res1, should print book titles of authors have name "andrei" in , res2 should print book titles have string "programare".

case class book(title: string, authors: list[string]){    val books: list[book] = list(    book("interpretarea programelor pe calculator",    list("grigore, alexe", "antonio, vucu g.")),    book("calcul diferential si integral",    list("andrei, ioan", "anghel, radulescu")),    book("introducere in limbajul de programare c++",    list("andrei, nicolae")),   book("introducere in programarea functionala",    list("dinu, constantin")),    book("programare in limbajul java",    list("daniel, iosif", "gicu, alin", "victor, niculescu ", "viorel,        andurache")))    val res1 = (b <- carti; <- b.authors if startswith "andrei") yield    b.title    val res2 = (b <- carti if (b.title indexof "programare") >= 0) yield b.title    def main(args: array[string]) {     println(res1);    println(res2);   } } 

so, lots of problems.

all stuff doing? it's getting done in constructor of book, , redone every instance.

your main method? that's gets compiled instance method of book, not static method, not serve an entry point executable program. can extend app dmitry suggests, or explicitly define main method in companion object rather class. companion object methods static "forwarders", end desired main method.

oh, , scala won't compile english romanian, if name variable books comprehensions can't work carti!

object book {   def main( argv : array[string] ) : unit = {     val books: list[book] = list(        book("interpretarea programelor pe calculator", list("grigore, alexe", "antonio, vucu g.")),        book("calcul diferential si integral", list("andrei, ioan", "anghel, radulescu")),        book("introducere in limbajul de programare c++", list("andrei, nicolae")),       book("introducere in programarea functionala", list("dinu, constantin")),        book("programare in limbajul java", list("daniel, iosif", "gicu, alin", "victor, niculescu ", "viorel, andurache"))     )      val res1 = (b <- books; <- b.authors if startswith "andrei") yield    b.title     val res2 = (b <- books if (b.title indexof "programare") >= 0) yield b.title      println(res1);     println(res2);   } } case class book(title: string, authors: list[string]) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -