Search code examples
scalaimplicitscala-3

What is the simplest way to create given for A & B type?


I have

trait Foo:
  def foo: Int

trait Bar:
  def bar: Int

given Foo with
  def foo = 1

given Bar with
  def bar = 1

And I have a function foobar

type FooBar = Foo & Bar
def foobar(using FooBar) = ...

What is the simplest way to create given for A & B type if I already have given A and given B


Solution

  • So, with everyone's help I think the simplest solution is

    given (using f: Foo, b: Bar): Foo with Bar with 
      export f.*
      export b.*