Skip to content

An experimental REST API project for testing functional programming capabilities in TypeScript.

License

Notifications You must be signed in to change notification settings

grzpab/fp-backend

Repository files navigation

fp-backend

An experimental REST API project for testing functional programming capabilities in TypeScript.

Stack

  • Docker 2 / Docker-Compose 3
  • MySQL 8
  • Node.JS 13
  • TypeScript 4

Functional Programming Concepts

Effects and Side Effects

Taking this project as the context, I would define effectful functions as functions that:

  • produce no side effects (access global variables, mutate entry parameters, change I/O, throw exceptions etc.),
  • have only one single main effect - they either return a function or an object.

Functions with side effects would be functions that are not effectful.

The aforementioned division allows me to split the projects into two classes of functionality:

  • functions that can be safely and fully tested because of their predictability,
  • functions that explicitly connect to the outside world.

TaskEither

The most fundamental structure in this project is TaskEither<E, A> which is a composition of two types:

  • Task<R> - an FP type representing a result of type R of a non-throwing asynchronous operation,
  • Either<E, A> - an FP union type representing either an error of a type E or a value of type A.

As most of our operations are asynchronous and may fail, we need to use TaskEither as the return type from functions that communicate with the outside world.

I decided to represent the error type as ProductError for convenience's sake.

Install and Run

docker network create fp-local-network
docker-compose up --build

About

An experimental REST API project for testing functional programming capabilities in TypeScript.

Resources

License

Stars

Watchers

Forks