2016-07-22 5 views
0

MyData 사례 클래스에 문자열지도를 작성하는 데 이해하려고 노력합니다. 여기yield map 이해를 돕기 위해

내가 실패 뭘하려 :

case class MyDataProperty(name: String, value: String) 
case class MyData(props: List[MyDataProperty]) 


def makeMyData(configs: List[Config]): Map[String, MyData] = { 
    for { 
     // loop through all configurations 
     conf <- configs 
     // Retrieve each config's list of properties and make a list of MyDataProperty object from it 
     props <- for(prop <- conf.properties) yield (MyDataProperty(prop.name, prop.value)) 
    } yield (conf.name -> MyData(props)) toMap 
} 

이 코드는 나를 여러 컴파일 오류가 있습니다. 이해를 위해 이런 종류의 둥지를 만들고지도를 산출하는 올바른 방법은 무엇입니까? for comprehensions

+0

컴파일 오류가 무엇을 얻고있다? – tuxdna

답변

0

코드는 다음과 같이한다 :

def makeMyData(configs: List[Config]): Map[String, MyData] = 
    (for { 
    conf <- configs 
    props = for (prop <- conf.properties) yield MyDataProperty(prop.name, prop.value) 
    } yield conf.name -> MyData(props)).toMap 
관련 문제