GenericTraversableTemplate에서 평평한 선언이 있고 Traversablelike가 아닌 이유는 무엇입니까?

StackOverflow https://stackoverflow.com/questions/1802828

문제

서명 TraversableLike.flatMap 다음과 같다:

def flatMap[B, Th](f : (A) => Traversable[B])(implicit bf : CanBuildFrom[Repr, B, Th]) : Th

서명 GenericTraversableTemplate.flatten 이다:

def flatten[B](implicit asTraversable : (A) => Traversable[B]) : CC[B] 

후자의 방법은 왜 (나에게 다른 것 같습니다. flatMap 변압기 기능이 있다는 의미에서만 implicit) 정의 할 수 없습니다 TraversableLike 처럼:

def flatten[B, Th](implicit asTraversable: (A) => Traversable[B], 
                   implicit bf : CanBuildFrom[Repr, B, Th]) : Th

이것이 사실이어야 할 이유가 있습니까?

도움이 되었습니까?

해결책

답은 소스 코드에 있다고 생각합니다.

def flatten[B](implicit asTraversable: A => /*<:<!!!*/ Traversable[B]): CC[B]

암시 적 매개 변수 flatten 실제로해야합니다 A <:< Traversable[B] (예 : 일반적인 매개 변수 GenericTraversableTemplate 그 자체입니다 Traversable). (보다 이 메일 링리스트 스레드 현재 댓글을 달린 이유에 대한 논의를 위해.) 내 이해는이 특성의 모든 방법이 일부 인스턴스화에만 적용 할 수 있기 때문에 (일부) 컬렉션 클래스의 동반자 객체에 정의되었다는 것입니다 (올바른 단어 인 경우). 유형 매개 변수. 이것 <:< 구성을 사용하면 인스턴스 방법을 만들 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top