Def send[A: SchemaFor: ToRecord](topic: String, message: A): Future[RecordMetadata]

I had seen a code in production with this signature.
def send[A: SchemaFor: ToRecord](topic: String, message: A): Future[RecordMetadata] = {}

I am not clear what send[A: SchemaFor: ToRecord] type is used for. Can someone please suggest here ??

Thanking you in advance Scala Community,

These are context bounds. It’s syntactic sugar for

def send[A](
  topic: String, message: A)(
  implicit schemaForA: SchemaFor[A], toRecordA: ToRecord[A]
): Future[RecordMetadata] = ???
3 Likes

To add to this, it typically intended to express capabilities. That’s also the case here: send a value of any type A, we don’t care what type A is, as long as there exists a scema for A and a way to turn A into a record.

These capabilities are expressed as implicit values: As long as there is a value in implicit scope of type SchemaFor[A] that describes the schema for A, and a value of type ToRecord[A], that describes how to turn A into a record, you can call the send method with that A.

1 Like

Thanks for your response