Make it optional

Report a typo

We want to develop a function to search for a user's login by its ID. We cannot guarantee that a login will be found by any identifier. Write such an ADT so that we can operate with strings that may or may not be there.

You don't have to implemnt findLoginById function, but the following code should compile without warnings:

def findLoginById(id: Long): OptionalString = ???

import OptionalString.*

findLoginById(42) match
  case Some(login) => s"Hi, $login!"
  case None        => "Incorrect id!"

Sample Input 1:

Sample Output 1:

Write a program in Scala 3
// define your OptionalString here
___

Create a free account to access the full topic