Comments (3)
Ah right. thanks for the kind response.
Closed for now. ^^
from fpdart.
I already solved it with
TaskEither<AppError, Response> _request(String url) => TaskEither<AppError, Response>.tryCatch(
() async => await dio.get(url),
(error, stackTrace) => AppError.from(error as Exception),
).chainEither(
(response) => Either.tryCatch(
() {
if (response.statusCode != 200){
Either.left(AppError.fromResponse(response));
}
return response;
},
(_, __) => AppError.fromResponse(response),
),
);
I changed it from Either.fromPredicate to Either.tryCatch
I am not sure if this is best practice of fp.
from fpdart.
Hi @radikz
In your first example the issue is that _validResponseBody
returns Either<E, String>
, while the type on your TaskEither
is TaskEither<AppError, Response>
(so Response
instead of String
). That's because you are mapping (map
) the Response
to String
using .map((r) => r.data);
.
Your second example works because in your tryCatch
you just return Response
(return response;
) instead of response.data
.
Does this make it more clear?
from fpdart.
Related Issues (20)
- fpdart sortBy is very slow and time processing scales very quickly HOT 3
- Add methods to convert `IO` to other classes (`TaskEither`, `TaskOption`, `IOEither`)
- Llinks are not working HOT 1
- fpdart v1.0.0 HOT 20
- Add getOrThrow for Either TaskEither HOT 1
- slight typo in lib/src/class/applicative.dart
- catch only specified exceptions vs all HOT 1
- Difference between `IOEither` and `Either` HOT 1
- change match/fold extension for bools to named parameters HOT 2
- Show example in docs of mixing functional packages and renaming classes HOT 2
- Add an extension on`Function` which convert a function that returns `Either` to async one HOT 1
- Implement built-in conversions to Option and Either (e.g. `toIntOption()`) HOT 3
- Getter properties to simplify syntax HOT 1
- Does fpdart have an `orElse` for IO ? HOT 1
- Either of void HOT 3
- How to return Unit HOT 2
- Option losing alt and foldable HOT 1
- Issue: Version 0.4.1 creates Type Exception on getOrElse HOT 2
- foldLeft documentation is incorrect 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 fpdart.