Comments (6)
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.
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.
So basically when you need to transform the error as it is passing through is my biggest use case.
from scalatest.
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.
Awesome thanks! And thanks for ScalaUtils. I love it.
from scalatest.
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)
- Add a `maxFailedAssertions` configuration for property based tests in `PropertyCheckConfiguration` HOT 1
- Access Scenario name from inside a scenario? HOT 2
- AsyncFunSuite and StepwiseNestedSuiteExecution do not work together HOT 5
- Measuring duration of beforeAll, afterAll, beforeEach, afterEach HOT 1
- Question: dependency between tests for ParallelTestExecution HOT 2
- Diagrams.assert calls Future two times HOT 1
- Better user error if User extends a Spec with parameters? HOT 1
- PrivateMethodTester fails for AnyVal types HOT 1
- Replaying a Seed for ScalaCheck does not work as expected. HOT 2
- using `assert(x.size(1) == 3)` in a test, triggers a wrong compiler warning HOT 4
- [Feature] Scalatest is not able to create aggregated "index.html" report for different modules/subprojects HOT 1
- ScalaTest runner issue with SBT, scala.js and Slow test selections HOT 10
- Routes Test Not Running - False Positive HOT 1
- [IJ] AnyWordSpec doesn't run single test HOT 6
- Suites should report its own SuiteStarting event before running its nested suites
- Add a way to run a ScalaCheck test with a given seed HOT 4
- Not Useful scala.MatchError given while failing Tests HOT 2
- Opaque Types don't verify correctly (Maybe ?) HOT 6
- FBounded Polymorphism and `shouldNot compile` giving a false positive HOT 6
- WordSpecLike HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scalatest.