Last active
August 29, 2015 13:57
-
-
Save frozenspider/9376005 to your computer and use it in GitHub Desktop.
Different formats of one-liners
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
// Ugly one-liner: type is in the middle of the line, implementation takes less than half a line | |
// Pain! | |
implicit class RichSsWorkbook(wb: Workbook) { | |
def apply(i: Int): Sheet = wb.getSheetAt(i) | |
def bytes: Array[Byte] = { | |
val baos = new ByteArrayOutputStream | |
wb.write(baos) | |
baos.toByteArray | |
} | |
} | |
// Beautiful, structured multi-liner | |
// You can see the type ane implementation in one look! | |
// A pleasure to watch | |
implicit class RichSsWorkbook(wb: Workbook) { | |
def apply(i: Int): Sheet = | |
wb.getSheetAt(i) | |
def bytes: Array[Byte] = { | |
val baos = new ByteArrayOutputStream | |
wb.write(baos) | |
baos.toByteArray | |
} | |
} | |
// These one-liners are okay though - no return types and they are grouped together | |
implicit class RichSsWorkbook(wb: Workbook) { | |
def test1(i: Int) = wb.getSheetAt(i) | |
def otherTest2(i: Int) = wb.getSheetAt(i) | |
def evenTesterTest3(i: Int) = wb.getSheetAt(i) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment