6

In specs2 there is a method called Around, documented here that has the following example:

object http extends Around {
  def around[T <% Result](t: =>T) = openHttpSession("test") {
    t  // execute t inside a http session
  }
}

The source for this code can be found here.

I'm curious what the <% operator means in this context?

EDIT: here is a solid answer on this subject, What are Scala context and view bounds?

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Jeff Wu
  • 2,428
  • 1
  • 21
  • 25
  • 2
    Google is painful to use to search for symbols, but PDF viewers are pretty good: take a look at the [Scala Language Specification](http://www.scala-lang.org/docu/files/ScalaReference.pdf) (or "SLS"). The term for this type restriction is "View Bounds". –  Jul 17 '12 at 04:27
  • I had to use this symbol-specific search engine to find it: http://symbolhound.com/ – JulienD Oct 23 '16 at 11:01

1 Answers1

5

This is a view bound. It means, that the type T must be convertible to the type Result. For more information about type bounds I recommend you http://www.cs.uwaterloo.ca/~brecht/courses/702/Possible-Readings/scala/ProgrammingInScala.pdf, starting at page 61.

tgr
  • 3,557
  • 4
  • 33
  • 63