Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open meteo example #63

Merged
merged 18 commits into from Dec 16, 2022
Merged

Open meteo example #63

merged 18 commits into from Dec 16, 2022

Conversation

SandroMaglione
Copy link
Owner

@SandroMaglione SandroMaglione commented Oct 24, 2022

This PR introduces a new real example of how to use fpdart.

The example comes from the bloc's package, specifically the Open Meteo API.

This example aims to show how to refactor imperative code to functional programming using fpdart. The example contains both the original code as well as the refactored code. The goal is to show a 1-1 comparison between the two solutions.


As part of this PR, also some new methods have been added to make the refactoring more effective:

  • chainEither to TaskEither
  • safeCast (Either and Option)
  • safeCastStrict (Either and Option)
int intValue = 10;

/// Unhandled exception: type 'int' is not a subtype of type 'List<int>' in type cast
final waitWhat = intValue as List<int>;
final first = waitWhat.first;

/// Safe 馃幆
final wellYeah = Either<String, List<int>>.safeCast(
  intValue,
  (dynamic value) => 'Not an List!',
);
final firstEither = wellYeah.map((list) => list.first);

@SandroMaglione SandroMaglione added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 25, 2022
@jacobaraujo7
Copy link
Contributor

any news about this?

@SandroMaglione
Copy link
Owner Author

@jacobaraujo7 I am planning to complete the series of articles on the Open Meteo API (see part 1) before release, so that the example is released alongside a proper explanation.

@SandroMaglione SandroMaglione merged commit 201b3d0 into main Dec 16, 2022
@SandroMaglione SandroMaglione deleted the open_meteo_example branch December 16, 2022 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants