December 08, 2019

let%Everything ReasonML

Key Takeaways

let%Anything is a really cool module for ReasonML, Which allows you to create a module and use as with let%Module, lets take a look how to use. Since buckleScri...

let%Anything is a really cool module for ReasonML,

Which allows you to create a module and use as with let%Module, lets take a look how to use.

Since buckleScript have upgraded to 7++ by default and I am using bs-let for demo:

Create a module and method that you like, with let_.

Here I create a very basic module of MapEmpty with let_, that takes a parameter and returns a callback which will be used as promise.

module MapEmpty = {
  let let_ = (params, cb) => params->Belt.Option.getWithDefault("")->cb;
};

So we can use this module as %Module

 {
  let a = None;

  let%MapEmpty b = a;

  Js.log(b);
};

You can find very cool introduction on EggHead of how you can use with async/await to replace promise in ReasonML.

Although EggHead is using promise from got module, I like to use bs-fetch so that you don't have to write binding. Lets install bs-fetch

yarn add bs-fetch

And remember to add bs-fetch to your bsconfig file

Now we want to create a Fetch module that will call a ajax and return the json data

Module Fetch = {
  let perform = url =>
    Js.Promise.(
      Fetch.fetch(url)
      |> then_(Fetch.Response.json)
      |> then_(json => json |> resolve)
    );
}

and create the async method

Module Async = {
  let let_ = (prop, cb) => Js.Promise.then_(cb, prop);
}

so now you can use it like the way you want like Javascript async/await

{
  let%Async res = Promise.perform("http://www.your-json.com/xxx.json");

  Js.log(res); // here you will received the json
  Js.Promise.resolve();
};

Vibe Code to Glory - Side Projects 2026

AI Banana Flow

Web App

Check out this project

AI Banana Flow is an AI Image Generator with Visual Flow Editor. It allows users to create stunning AI-generated images through an intuitive visual flow editor. Connect prompts, generate images, and build creative workflows with the power of AI. Experience a new paradigm of creative freedom with precision control and visual workflow management.

Category: AI Image Generation

AI Banana Flow - AI Image Generation Web application by Max Li Bin

AI Banana Flow

Web

SG Passport Photo - Utility Web application by Max Li Bin

SG Passport Photo

Web

MyPhotoAI - Photography iOS application by Max Li Bin

MyPhotoAI

iOS

Interior AI: Room Designer - Design iOS application by Max Li Bin

Interior AI: Room Designer

iOS