Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- func anyCommonElements <T: SequenceType, U: SequenceType where T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element> (lhs: T, _ rhs: U) -> [T.Generator.Element] {
- var common : [T.Generator.Element] = []
- for lhsItem in lhs {
- for rhsItem in rhs {
- if lhsItem == rhsItem {
- common.append(lhsItem)
- }
- }
- }
- return common
- }*/
- trait Eq[A] {
- def eq(a1: A, a2: A): Boolean
- }
- trait SequenceType[T] {
- }
- implicit val constraint = new
- def anyCommonElements[T <: SequenceType, U <: SequenceType](lhs: T, rhs: U)
- (implicit cs: Constraint[T, U])
- (implicit ev: Eq[T])
- : {
- val common = new ArrayBuffer[T#Generator#Element]
- for {
- li <- lhs
- ri <- rhs
- if ev.eq(li, ri)
- } {
- common += li
- }
- common
- }
Add Comment
Please, Sign In to add comment