Created
January 31, 2013 09:29
-
-
Save lyricallogical/4681634 to your computer and use it in GitHub Desktop.
method-dependent-types なくても普通に返値型は変えられますよの話
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def toDate[Result](magnet: DateMagnet[Result]): Result = magnet.convert | |
trait DateMagnet[Result] { | |
def convert(): Result | |
} | |
object DateMagnet { | |
implicit def fromInt(tuple:(Int, Int, Int)) = new DateMagnet[java.util.Calendar] { | |
def convert() = { | |
val (year, month, date) = tuple | |
val c = java.util.Calendar.getInstance | |
c.set(year, month - 1, date, 0, 0, 0) | |
c | |
} | |
} | |
implicit def fromString(s:String) = new DateMagnet[java.util.Date] { | |
def convert() = new java.text.SimpleDateFormat("yyyy/MM/dd").parse(s) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment