I have four methods like these (here are only two of them):   def checkLeft(clickedIndex: Int): Option[Int] = {    val leftIndex = clickedIndex - 1    if (leftIndex >= 0 && clickedIndex % field.width != 0 && isEmptyCell(leftIndex))      Some(leftIndex)    else      None  }  def checkRight(clickedIndex: Int): Option[Int] = {    val rightIndex = clickedIndex + 1    if (rightIndex < field.size && clickedIndex + 1 % field.width != 0 && isEmptyCell(rightIndex))      Some(rightIndex)    else      None  }They all have similar structures. How I can reduce code duplication here? 
Refactor to reduce code duplication
scala