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 8388905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:34:38+00:00 2026-06-09T18:34:38+00:00

Given the following functions: def foo( a: A ): ValidationNEL[String,Seq[B]] = … def bar(

  • 0

Given the following functions:

def foo( a: A ): ValidationNEL[String,Seq[B]] = ...

def bar( b: B ): ValidationNEL[String,C] = ...

I would like to combine them such as to build a function, which calls foo then eventually calls bar on each elements in the produced Seq, such a to get a ValidationNEL[String,Seq[C]]:

def fooAndBar( a: A ): ValidationNEL[String,Seq[C]]

Documentation in Scalaz 7 is very short and I could not find any relevant example.

  • 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-09T18:34:40+00:00Added an answer on June 9, 2026 at 6:34 pm

    Do a hardcore traversal on the B sequence. Note that I used List here since Scalaz 7 doesn’t seem to have typeclass instances for Seq, however it should not be too hard to write your own if really needed.

    import scalaz.{ValidationNEL, Traverse, NonEmptyList}
    import scalaz.std.list.listInstance
    case class A(a: Int)
    case class B(b: Int)
    case class C(c: Int)
    
    def foo( a: A ): ValidationNEL[String,List[B]] = Validation.success(List(B(1), B(2)))
    def bar( b: B ): ValidationNEL[String,C] = Validation.failure(NonEmptyList("error in " + b.b))//Validation.success(C(b.b * 2))
    
    type ValNEL[A] = ValidationNEL[String, A]
    
    def foobar(a: A): ValidationNEL[String, List[C]] =
      foo(a) flatMap { bs =>
        Traverse[List].traverse[ValNEL, B, C](bs)(bar)
      }
    
    val r: scalaz.ValidationNEL[String, List[C]] = foobar(A(3))
    

    Update: Also see the invaluable Haskellwiki Typeclassopedia

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following function: def foo(a, b, c): pass How would one obtain a
Given is the following example: class Foo(object): def __init__(self, value=0): self.value=value def __int__(self): return
Suppose I have a the following in Scala object Foo { var functions: List[String
Given the following javascript: function foo(selectControl) { ... } and the following html: <select
Given the following code, How would you refactor this so that the method search_word
I have a problem using docstrings with decorators. Given the following example: def decorator(f):
Given the following: class MyClass: def __init__(self, someval): self.someval = someval def get_a_function(self): def
Given the following example code: def myfunc(item): if item == 2: item = 1
Given the following type and instance: type operation = (Int, Int) => Int def
Given the following HTML-Fragment: <div> <p> abc <span id=x>[</span> def <br /> ghi </p>

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.