DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Eric has posted 2 posts at DZone. View Full User Profile

More Idiomatic TalkingPuffin

06.30.2009
| 968 views |
  • submit to reddit
        if (selectedRow != -1) {
  cursorCandidates = ((selectedRow + 1) to table.getRowCount).foldLeft(Nil:List[Long]) { (res, cur) => 
     model.getStatusAt(table.convertRowIndexToModel(i)).id :: candidates
  }.reverse
}

// and 

// find then flatMap because find would return Option[Option[Long]]
cursorCandidates.find(model.getIndexOfStatus(_).isDefined).flatMap { id => 
  val viewIdx = table.convertRowIndexToView(i)
  table.getSelectionModel.addSelectionInterval(viewIdx, viewIdx);
  log.debug("Found cursor index from candidates: " + i)
}