나는이 질문이 중복 될 수 있다고 확신하지만, 이에 대한 답을 찾지 못했습니다. 스칼라에 대한 무지한 지식을 용서해주십시오. 나는 꽤 초보 다.만드는 방법 옵션 목록 [Double] in for 루프 스칼라
내 목표는 다른 길이의 두 목록을 반복하고 List[List[Option[Double]]]
을 반환하는 것입니다. 지금까지
내 코드 :
Vector(
Some(313.062468),
Some(27.847252),
Some(301.873641),
Some(42.884065),
Some(332.373186),
Some(53.509768)
)
그러나 나는 이런 식으로 뭔가를 반환 할 :
def getDoubles(symbol: String, year: Int): Option[Double] = {
return Some(140.0)
}
// this method loops over list of strings and range of time. returns list of list of Option[Double]
def checkList(CSV: List[String], time: Range): List[List[Option[Double]]] = {
// this variable is whats going to be returned at the end
var listOfLists = List[List[Option[Double]]]()
// So we are going to loop over our list and our time, and link each element in our list to all the elements in our time range
for {
i < -CSV
j < -time
// the method getDoubles is pretty long, so i just made another version simplfying my question.
// get doubles bascially returns Option of doubles
}
yield (listOfLists = getDoubles(j, i)::listOfLists)
return listOfLists
}
위의 코드, 좀 더 복잡한 데이터를 호출 할 때, 그것은 반환
List(
List(Some(313.062468), Some(27.847252)),
List(Some(301.873641), Some(42.884065)),
List(Some(332.373186), Some(53.509768))
)
어떻게하면됩니까?
이 경우는 간단하지만 나중에 사람들이 대답 코드에서 쉽게 시도 할 수 있도록 "정교한 데이터"(예 : 원하는 결과물을 제공해야 함)를 제공해야합니다. – laughedelic