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)
- Opaque Types don't verify correctly (Maybe ?) HOT 6
- FBounded Polymorphism and `shouldNot compile` giving a false positive HOT 6
- WordSpecLike HOT 3
- Passing position explicitly to test in Scala 3 HOT 5
- Need support for com.vladsch.flexmark:[email protected] HOT 3
- Retry test with delay HOT 5
- assertDoesNotCompile not works when creating mixins HOT 4
- StackDepthException.failedCodeStackDepth returns invalid value `0` when using Future + passing custom implicit position HOT 4
- Passing assert message by-name? HOT 3
- Unexpected compilation warnings: Auto-application to `()` is deprecated. HOT 5
- PrivateMethodTester does not correctly honor type bounds for method arguments HOT 1
- only method not working in Scala 3 Matchers (as List) HOT 1
- InsertionOrderSet performance issue HOT 5
- what's the right way to use scalatest with scalatestplus.junit5? HOT 2
- add back Mockito 4 support? HOT 3
- Shell.run doesn't fail, it would be nice if it could HOT 2
- Execute tasks on SerialExecutionContext outside of a test HOT 1
- Publish artifacts for Scala-Native 0.5.0? HOT 4
- === method causes conflict in Scala 3
- ScalaTest all release jar files are empty and file size is 1kb HOT 2
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.