object(index)
. How can you do that in scala?This topic is derived from How do I setup multiple type bounds in Scala?
Answer:
- scala> def process[R <: Function1[Int,String] with Iterable[String]] (resource:R) = {
- | println("using function:"+resource(0))
- | println("using iterable:"+resource.elements.next)
- | }
- process: [R <: (Int) => String with Iterable[String]](R)Unit
- // Array is a Function1 and iterable so this works
- scala> process (Array("1","2","3"))
- using function:1
- using iterable:1
No comments:
Post a Comment