Skip to content

Latest commit

 

History

History

open_meteo_api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Open Meteo API - fpdart

This is a re-implementation using fpdart and functional programming of the Open Meteo API from the flutter_weather app example in the bloc package.

The goal is to show a comparison between usual dart code and functional code written using fpdart.

Structure

The example is simple but comprehensive.

The Open Meteo API implementation is only 1 file. The original source is open_meteo_api_client.dart (copy of the bloc package implementation).

Inside lib/src/fpdart you can then find the refactoring using functional programming and fpdart:

Test

Also the test has been rewritten based on the fpdart refactoring:

Types used from fpdart

  • TaskEither: Used instead of Future to make async request that may fail
  • Either: Used to validate the response from the API with either an error or a valid value
  • Option: Used to get values that may be missing
    • lookup in a Map: getting a value by key in a Map may return nothing if the key is not found
    • head in a List: The list may be empty, so getting the first element (called "head") may return nothing