Skip to content

Extract library code to new lib_base

Rémy El Sibaïe requested to merge extract-library-code into develop

Context

We had several issues that we wanted to handle

  • We had several versions of std lib extensions: <Module>Ex.re files, UmamiCommon, etc.
  • Future.t(Result('a, Errors.t)) is not enforced anywhere

It is not possible to use -open to open a module everywhere because it would open itself and create a circular dependency 🤦 .

Contribution

Stdlib

We chose to create an external library, lib_base. In this library, we extend Belt.<Module> by creating a file <Module>.re with include Belt.<Module> as first line.

Now if you want to add a function that operate over list or option you can add it in the corresponding module. UmamiLibBase is opened everywhere with -open.

Future

We created a new module Promise with type t('a) = Future.t(Result.t('a, Errors.t));. We also replaced every calls to Future by Promise and renamed let-bindings adequately.

Let-bindings

let%Await = ...  // Promise.flatMapOk

let%AwaitMap = ...  // Promise.mapOk

let%AwaitRes = ...  // m->Promise.flatMapOk(x => n->Promise.value)
                    // the computation on the right of the equal is a promise
                    // but the rest of the computation should be a result 
                    // useful to chain %Res after %Await
Edited by Rémy El Sibaïe

Merge request reports