yield - Scala beginner for-comprehensions and functions -
hey guys new scala , dont knowe doing wrrong right typ yield statement:
def prim(n:int): (boolean, list[int]) = divsers(n) -> list(1,n) //flatmap for-comprehensions def divsers(n:int):boolean= (for{ d <- 1 n if((n%d)->0) }yield(d) // <- need put here make work function prim? ) prim(11); i want test if number prime number. realy have got realy problems syntac , typs.even if put "true" in yield dont work?
you're doing kinds of things make no sense.
divsers(n) -> list(1,n) point of returning tuple who's 2nd element list of 2 ints? 1st int 1 , 2nd int number passed argument prim().
if((n%d)->0) you've created tuple here. mean if (n%d) > 0.
yield ? for comprehension walking through sequence of numbers 1 n. of them pass through if condition , won't. you've got new list of numbers. how you're supposed turn boolean you.
Comments
Post a Comment