Give me my toy!

Report a typo

You are developing a program for a toy slot machine game. The program implementation takes a line as input and converts each string to a particular toy class, the _ character indicating no won toy. The parsing is already written, and, as a result, we have a list of None or Some with an instance of a particular toy. Since there are too many toy classes, they disobey the general hierarchy, AnyRef was used.

Implement a function that can count their number without knowing the type of each toy.

Sample Input 1:

SuperToy _ SimpleToy

Sample Output 1:

2
Write a program in Scala 3
def toysNumber(toys: List[Option[AnyRef]]): Int =
??? // implemnt here

Create a free account to access the full topic