Skip to content

Instantly share code, notes, and snippets.

@frozenspider
Last active August 29, 2015 13:57
Show Gist options
  • Save frozenspider/9376005 to your computer and use it in GitHub Desktop.
Save frozenspider/9376005 to your computer and use it in GitHub Desktop.
Different formats of one-liners
// 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