Currently I use this to pick the first element of a list:
def Get_Read_Key =
{
logger.entering (TAG, "Get_Read_Key")
val Retval = if (Read_Key_Available)
{
val Retval = Keystrokes.head
Keystrokes = Keystrokes.tail
Retval
}
else
{
calculator.ui.IKey.No_Key
} // if
logger.exiting (TAG, "Get_Read_Key", Retval)
Retval
} // Get_Read_Key
def Read_Key_Available = Keystrokes.size > 0
But it looks all kind of clumsy — especially the double ´Retval´. Is there a better way of doing this? Or is it just the price to pay for using an immutable list?
Background: The routine is used on a Unit Test Mock class – return types are set.
You’re implementing an
Iteratoron aList, that’s already in the standard library.