I have the following method:
def generateAssociatedImages : List[ImageFileEntry] = {
if ( this.page > 1 && this.page < this.fileEntry.pageCount ) {
List( copyWithPage( this.page - 1 ), copyWithPage( this.page + 1 ) )
} else {
if ( page == 1 && page != file.fileEntry.pageCount ) {
List( copyWithPage( this.page + 1 ) )
} else {
List( copyWithPage( this.page - 1 ) )
}
}
}
But this one looks too much like Java (if I was using Ruby I’d do a switch/case on a range and then do the other comparisons). Is there a more funcional way to do this in Scala?
The behavior is quite simple:
- if input is page 1 and total pages is 3, the output is [2]
- if input is page 2 and total pages is 3, the output is [1,3]
- if input is page 3 and total pages is 3, the output is [2]
I’m looking for an idiomatic solution, I’m still new to Scala.
It would be lovely if I could do something like:
( 1 until 3 ).hasNext( 2 )
Assuming that on a one page, the list of images is empty, you can have the following: