Code Monkey home page Code Monkey logo

Comments (6)

bvenners avatar bvenners commented on May 10, 2024

A bad-map. Interesting and makes sense. Just for context, can you give a specific example where you want to keep the good side the same if it is good, but transform the bad if it is bad?

from scalatest.

bigjason avatar bigjason commented on May 10, 2024

Sure. A bit contrived but you get the idea:

def findUser(id: Long): User Or ErrorCode = ???

findUser(123).bmap {
  case Missing => "User was not found"
  case Error => "Internal error, please try again later"
}

Also when integrating with Try

def findUser(id: Long): Try[User] = ???

Or.from(findUser(123)).bmap {
  case exc: MissingValueException => "User was not found"
  case _: Throwable => "Internal error, please try again later"
}

from scalatest.

bigjason avatar bigjason commented on May 10, 2024

So basically when you need to transform the error as it is passing through is my biggest use case.

from scalatest.

bvenners avatar bvenners commented on May 10, 2024

Hi Jason,

I see. Makes sense. I'll add something like that in the next release.

Bill

On Fri, Dec 13, 2013 at 10:30 AM, Jason Webb [email protected]:

Sure. A bit contrived but you get the idea:

def findUser(id: Long): User Or ErrorCode = ???
findUser(123).bmap {
case Missing => "User was not found"
case Error => "Internal error, please try again later"}

Also when interpolating with Try

def findUser(id: Long): Try[User] = ???
Or.from(findUser(123)).bmap {
case exc: MissingValueException => "User was not found"
case _: Throwable => "Internal error, please try again later"}


Reply to this email directly or view it on GitHubhttps://github.com//issues/197#issuecomment-30531848
.

Bill Venners
Artima, Inc.
http://www.artima.com

from scalatest.

bigjason avatar bigjason commented on May 10, 2024

Awesome thanks! And thanks for ScalaUtils. I love it.

from scalatest.

bvenners avatar bvenners commented on May 10, 2024

I have checked a badMap method for Or into the 2.1.x branch, which is queued to go out as 2.1.0 final shortly. It is also merged into master. I also added a fold method. Thanks for the suggestion.

from scalatest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.