question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Derive a custom Validate from an existing one

See original GitHub issue

First let me apologize for creating an issue for a simple question, but I haven’t found another channel.

So, let’s say I would like to refine scala.concurrent.duration.FiniteDuration, e.g. with Positive. My first idea was to simply use Positive and (contra)map it over a function extracting the length from the FiniteDuration which is a Long. But I haven’t found a way to do that, i.e. no public (contra)map method on Validate.

Any help would be highly appreciated.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hseebergercommented, Jan 1, 2018

Thanks for the quick answer!

I have changed the title (removed “question”) to better reflect the new nature of this issue (now a feature requirement).

0reactions
Primetalkcommented, Dec 12, 2018

For deriving a custom Validate from existing one we might need an equivalence relation:

  final class Equivalence[A, B]

  private val equivalenceInstance = new Equivalence[Any, Any]

  type `<==>`[A, B] = Equivalence[A, B]

  implicit def inferEquivalence[T,A,B](implicit eab: A ==> B, eba: B ==> A) : A <==> B = 
    equivalenceInstance.asInstanceOf[A <==> B]

And then we want to have the following validation inference rule:

  implicit def equivalenceValidation[T, A, B](implicit v: Validate[T, A], e : A <==> B): Validate[T, B] =
    v.asInstanceOf[Validate[T, B]]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Custom Form Validators: Complete Guide
The Angular Forms module needs to know what are the multiple custom validation directives available. It does so by asking the dependency ...
Read more >
validator - Rust - Docs.rs
This trait will be implemented by deriving Validate . This implementation can take one argument and pass this on to custom validators.
Read more >
Custom Data Validation in Excel : formulas and rules - Ablebits
If you want to validate cells with your own criteria, create a custom validation rule based on a formula. Here's how: Select one...
Read more >
Custom Validators — FluentValidation documentation
There are several ways to create a custom, reusable validator. The recommended way is to make use of the Predicate Validator to write...
Read more >
Throwing a Custom Validation Exception - Oracle Help Center
When defining object level validation rules or triggers, normally the declaratively-configured error message will be sufficient for your needs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found