Scala implicit Implicit conversions implicit def stringWrapper(s: String) = new RandomAccessSeq[Char...

Please Visit: http://ift.tt/1ajReyV

Scala implicit
Implicit conversions
implicit def stringWrapper(s: String) = 
new RandomAccessSeq[Char] {
  def length = s.length
  def apply(i: Int) = s.charAt(i)
}
stringWrapper("abc123") exists (_.isDigit)
"abc123" exists (_.isDigit)
Implicit parameters
import JoesPrefs._    
Greeter.greet("Joe")
http://ift.tt/1h0CONM

if such a method misses arguments for its implicit parameters, such arguments will be automatically provided.
http://ift.tt/11WtfZz


implicit class StringImprovements(val s: String) {
    def increment = s.map(c => (c + 1).toChar)
}
import com.alvinalexander.utils.StringUtils._
println("HAL".increment)
http://ift.tt/1D5gN6s

For an implicit class to work, its name must be in scope and unambiguous, like any other implicit value or conversion.
http://ift.tt/JRtmfU



from Public RSS-Feed of Jeffery yuan. Created with the PIXELMECHANICS 'GPlusRSS-Webtool' at http://gplusrss.com http://ift.tt/1Omfiuz
via LifeLong Community

No comments:

Post a Comment