An experimental REST API project for testing functional programming capabilities in TypeScript.
- Docker 2 / Docker-Compose 3
- MySQL 8
- Node.JS 13
- TypeScript 4
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.
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 typeR
of a non-throwing asynchronous operation,Either<E, A>
- an FP union type representing either an error of a typeE
or a value of typeA
.
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.
docker network create fp-local-network
docker-compose up --build