Skip to content

cinxgler/inviter

Repository files navigation

Experimenting with Typed Functional Programming in Python

This is a toy app that uses results library to build a module that follows basic principles of Typed Functional Programming, inspired on the following articles and books

The module implements a simple app that sends an invitation to adults from a list of people (including underage). This have two user interfaces, command line and REST API.

Modules

The inviter package has the following modules:

  • inviter/domain.py: Contains the core types to model people for this app, it contains the invariants and factory functions that allow to build the required entities.
  • inviter/exceptions.py: Include a simple InvariantException that is raised when a Invariant is broken in the domain. The exception requires a ErrorCode to state the type of error found.
  • inviter/io.py: It contains the function sends an invite, the function is impure and can fail randomly.
  • inviter/repository. It contains functions that retrieves people data from memory or a json file people.json, they return entities using the domain types.
  • inviter/usecase.py: It contains the main use case that receives a DateTime value that stated when the invited person should attend to the event. It fetches the people, filter by adults, build the invitation and sends the invite. Dependencies to repository and IO are given as parameters.

Run

  • Create virtual environment and install dependencies

      virtualenv -p python3.8 venv
      source venv/bin/activate
      pip install -r requirements.txt
    
  • Run command line interface

      python main.py invite_adults "1978-09-15 10:00"
    
  • Run web api

      python main.py webserver
    
  • You can run the test suite using and get the coverage HTML report htmlcov folder

      pytest
    
  • You can check the typing using

      mypy
    

Pantsbuild commands

This repository has pantsbuild configured to manage a mono repository

To bootstrap the tool in your computer you just need to have internet connection and run

     ./pants

Later you can run the following commands:

  • You can run the test suite using and get the coverage HTML report htmlcov folder

      ./pants test ::
    
  • You can run linter and formatters running:

      ./pants lint ::
    

(WIP) The typecheck goal is not currently working due an issue with dependencies.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published