Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8587509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:35:11+00:00 2026-06-11T22:35:11+00:00

I have a function with the following signature def reject[A](errors: List[String]): ValidationNEL[String, A] Since

  • 0

I have a function with the following signature

def reject[A](errors: List[String]): ValidationNEL[String, A]

Since this is a reject method, the type A would never be returned but I need it to be reflected in order to match the signature. I was messing around with type lambdas to get my desired result as follows:

errors.map(Failure[String, A](_).liftFailNel).sequence[({type l[a] = ValidationNEL[String, a]})#l, A]

This uses the type List[A] (or appears to), rather than my desired type A. Is there a standard way to derive the result I am looking for?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:35:13+00:00Added an answer on June 11, 2026 at 10:35 pm

    Because errors may be an empty List, and you are constraining yourself to have no value of type A, I don’t think you can write this as a total function. To write this type signature, you would need to cheat by pretending the empty list case does not exist, e.g.

    def reject[A](errors: List[String]): ValidationNEL[String, A] =
      Failure(errors.toNel.get) // bad!
    

    Edit: As Apocalisp pointed out, you can of course make this a total function, by introducing an error for the empty list. But I would only do that if errors is computed at runtime, and I suspect this is not your use case, as it would lead to silly errors such as:

    def reject[A](errors: List[String]): ValidationNEL[String, A] =
      Failure(errors.toNel getOrElse NonEmptyList("Error: There were no errors!"))
    

    Why not pass the errors as a NonEmptyList instead – presumably you only use this function if you have errors to use at compile time.

    def reject[A](errors: NonEmptyList[String]): ValidationNEL[String, A] =
      Failure(errors)
    

    You can make this terser to use by copying the signature of NonEmptyList.apply (and specialising it to String):

    def reject[A](h: String, t: String*): ValidationNEL[String, A] =
      Failure(NonEmptyList(h, t: _*))
    

    Let’s try it out:

    scala> reject("foo", "bar", "baz")
    res0: scalaz.package.ValidationNEL[String,Nothing] = Failure(NonEmptyList(foo, bar, baz))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function having the following signature: def action_handler(request, model): This action_handler
Assume I have a method/function with the following signature: foo($bar = 0) Inside foo
I have a C function with the following method signature. NSString* md5( NSString *str
I have a C function with the following signature: int my_function(int n, struct player
I have the following function using Excel 2010: Private Function MakeAllSheetsValuesOnly(targetBookName As String) If
I'm getting a strange error. I have a function of the following signature: template
I have a unmanaged C++ function with the following signature: int function(char* param, int
I have a function with the following signature: float* Interpolate(float t, UINT iOrder, UINT
A template function I have written has the following signature: template<class IteratorT> auto average(IteratorT&
For a numeric intensive code I have written a function with the following signature:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.