Show

Report a typo

You have three values: serverName of type String, time of type Int, and status of type Boolean. You want to display the results in the format s"$time: $serverName is alive: $status".

To achieve this, you need to define an implicit instance of the Show type class for the tuple (String, Int, Boolean). This instance will allow you to convert the tuple to the desired format.

trait Show[A]:
  def show(a: A): String

Then it will be used in this showValue function:

def showValue[A](a: A)(using showInstance: Show[A]): String =
   showInstance.show(a)

Sample Input 1:

srvg169 150 true

Sample Output 1:

150: srvg169 is alive: true
Write a program in Scala 3
trait Show[A]:
def show(a: A): String

object Show:
given Show[TYPE_IN] = ???
___

Create a free account to access the full topic