대괄호 및/또는 마침표를 생략 할 수 있는지 여부를 이해하는 데 가장 힘든 시간을 보내고 있습니다. 이것은 _과 상호 작용합니다.명명 된 매개 변수 vs _, 점 표기법 v 중위 연산자 v 스칼라에서 고차 함수를 사용할 때 중괄호 대괄호 대괄호
내가이 함께했다 특정 경우
이val x: X = ???
val xss: List[List[X]] = ???
xss map x :: _ //this doesn't compile
xss map _.::(x) //this is the same as the above (and thus doesn't compile)
위의 두 가지가 한편 xss.map(_).::(x)
xss map (x :: _) //this works as expected
xss map {x :: _} //this does the same thing as the above
동일 것 같다이었다, 다음도 실패 :
xss.map xs => x :: xs //';' expected but '=>' found.
xss.map x :: _ //missing arguments for method map in class List; follow this method with `_' if you want to treat it as a partially applied function
//so when I try following the method with _, I get my favourite:
xss.map _ x :: _ //Cannot construct a collection of type That with elements of type B based on a collection of type List[List[Main.X]]
//as opposed to
xss map _ x :: _ //missing parameter type for expanded function ((x$1) => xss.map(x$1).x(($colon$colon: (() => <empty>))))
오른쪽 지금, 나는 종종 "컴파일 될 때까지 심볼을 토글 (toggle)"하고 플레이한다. 차선책의 프로그래밍 전략. 이 모든게 어떻게 작동합니까?
http://stackoverflow.com/questions/2173373/scala-foreach-strange-behaviour를 보았습니까? – sschaef
아직 감사합니다. 찾고. – Martijn
이것은 괄호/점을 생략 할 수있는 문제에 도움이됩니다. http://stackoverflow.com/questions/1181533/what-are-the-precise-rules-for-when-you-can-omit-parenthesis- 도트 중괄호 -f – sschaef