Skip to content

Instantly share code, notes, and snippets.

@coacoas
Created May 15, 2014 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coacoas/8d7f90b99a0c93ca0fc5 to your computer and use it in GitHub Desktop.
Save coacoas/8d7f90b99a0c93ca0fc5 to your computer and use it in GitHub Desktop.
TypeClass in Scala
/*
* Copyright (c) 2001, 2014, Object Innovation, Inc. All Rights Reserved.
*
* This software is published under the terms of the Object Innovation License
* version 1.1, a copy of which has been included with this distribution in the
* LICENSE.TXT file. Learn more at http://www.bridgegatetei.com
*/
package com.oidev.bridgegate
/**
* Created by bcarlson on 5/15/14.
*/
object Example {
def wiggle[A](a: A): String = ???
trait Show[A] {
def show(a: A): String
}
def wobble[A : Show](a: A): String =
implicitly[Show[A]].show(a)
implicit object IntShow extends Show[Int] {
def show(a: Int): String = s"Integer: ${a.toString}"
}
wobble(3)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment