Skip to content

Instantly share code, notes, and snippets.

@johnkpaul
Created July 17, 2011 01:21
Show Gist options
  • Save johnkpaul/1087002 to your computer and use it in GitHub Desktop.
Save johnkpaul/1087002 to your computer and use it in GitHub Desktop.
Implicit conversions in scala
class Mixin(value: Int){
def myCrazyNameOperator(f: Int => Int) : Int = f(value)
}
implicit def toWTF(value: Int) = new Mixin(value);
def double(int: Int) = {2 * int}
def triple(int:Int) = {3 * int}
@papajuans
Copy link

English, please.

@johnkpaul
Copy link
Author

I don't know if I can really give you a satisfying answer because I don't understand it completely myself. Apparently scala allows what are called implicit conversions that allow conversion methods that take type parameters that are implicitly called in such a way that it seems like I can add methods to any existing class. http://www.codecommit.com/blog/ruby/implicit-conversions-more-powerful-than-dynamic-typing

One day I will understand this better and be able to give a better explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment