1

I've tried this two options:

object DSChecker {
  implicit def checkImplFunction(dataset: Dataset[Row], config:Config): Checker = new Checker (dataset, config)
}

and

object DSChecker {
  implicit def checkImplFunction(dataset: Dataset[Row])(implicit config:Config): Checker = new Checker (dataset, config)
}

They compile, but the problem is when I need two use them.

I've tried also multiple combinations, but they don't compile... (evalDifferences is a "normal" function inside clas Checker)

//Whithout implicit args in implicit function
import DSChecker._
(df1, difConfig).evalDifferences(df2)

or

// With config as implicit arg in implicit funciton
import DSChecker._
df1.evalDifferences(df2)

The problem is always the same... the compilator doesn't find "evalDifferences" method.

Can someone help me?

1
  • 3
    Sounds like you might be looking for an extension method instead. Commented Jan 5, 2022 at 12:21

2 Answers 2

3

In your case, I think extension method fits better:

object DSChecker {
  implicit class DfExtension(df: Dataframe) {
    def checker(implicit config: Config) = {
      new Checker(df, config)
    }
  }
}

df1.checker.evalDifferences(df2)

You can also expose evalDifferences directly as extension method.

Sign up to request clarification or add additional context in comments.

Comments

1

Try with Tuple:

object DSChecker {
  implicit def checkImplFunction(data: (Dataset[Row], Config)): Checker = new Checker (data._1, data._2)
}

Then, this should work:

//Whithout implicit args in implicit function
import DSChecker._
(df1, difConfig).evalDifferences(df2)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.