Profile picture
🔥 Josh Branchaud 🕺🏼 @jbrancha
, 70 tweets, 74 min read Read on Twitter
Day 12: Using ANSI escape sequences to make things printed to the terminal a bit more colorful. Learned that @ReasonML wants escape sequences in decimal (i.e. \027). #100DaysOfCode #ReasonML buff.ly/2ubnrf0
Still need to mess around with background colors and modifiers (e.g. bold, italics, underline).
Day 13: An iteration on yesterday's -- I'm using @ReasonML's variant type to create `foreground_color` which I switch on to get the color codes; hopefully improving readability. #100DaysOfCode #ReasonML github.com/jbranchaud/ter…
Day 14: Created a linked list module using @ReasonML's variants with type arguments ('a). This example is a linked list of ints, but it could be strings, bools, or some more complex type. #100DaysOfCode #ReasonML github.com/jbranchaud/lin…
Day 15: Following the @ReasonML convention of adding a `make(n, x)` function to my LinkedList implementation (see above). This involved writing a rec(ursive) function and doing some bounds handling. #100DaysOfCode #ReasonML github.com/jbranchaud/lin…
Day 16: Taking this LinkedList implementation a bit further with an `iter(fn, list)` function. Using @ReasonML's rec(ursive) functions to achieve this in just a couple lines. #100DaysOfCode #ReasonML github.com/jbranchaud/lin…
Day 17: Using some low-level goodies from @ReasonML's Unix module to read bytes from a file. #100DaysOfCode #ReasonML github.com/jbranchaud/rea…
Day 18: Using some less low-level goodies (from @ReasonML's Pervasives module) to read a line from a file. This takes much less ceremony and byte-wrangling than yesterday's. #100DaysOfCode #ReasonML github.com/jbranchaud/rea…
Day 19: Doing more stuff with files in @ReasonML -- this is a clone of `touch` using some Unix module features like:
- O_CREAT openfile flag
- formatting file_perm type
- utimes() to update access/modify times
#100DaysOfCode #ReasonML github.com/jbranchaud/tou…
Day 20: Spent a bit of time trying to get various OCaml testing libraries to work with @ReasonML and bsb-native -- then I realized I can make do with the builtin `assert()` function. #100DaysOfCode #ReasonML
Day 21: Polishing up my @ReasonML assertion code from yesterday by putting it in a module, raising a custom exception when it fails, and returning unit `()` when it passes. #100DaysOfCode #ReasonML
Day 24: Here is a @ReasonML version of Selection Sort, again with lots of mutation. Being able to offload a bunch of cognitive energy on the static type system/compiler makes it much easier to get an algorithm right the first time. #100DaysOfCode #ReasonML github.com/jbranchaud/sor…
Day 25: I sketched out a @ReasonML function to swap two values in an array, hit save, and refmt goes, "Actually, you should have written it like this." Noted! #100DaysOfCode #ReasonML
Day 26: Yesterday I mob programmed a @ReasonML guessing game with my @Hashrocket crew. It blows my mind how readable you can make things with well-named variants. #100DaysOfCode #ReasonML github.com/jbranchaud/gue…
Day 27: Here is a colorful wrapper around a gnarly git command for displaying the most recently accessed branches. Figured out how to stream lines from a file in @ReasonML for this one. #100DaysOfCode #ReasonML github.com/jbranchaud/git…
Day 28: Found out about @ReasonML's application operator (@@) which allows you to apply a function to an argument. Potential use case below with a function-returning switch statement. #100DaysOfCode #ReasonML github.com/jbranchaud/git…
Day 29: Using a couple recursive functions to create a much more palatable version of Insertion Sort -- ditching the imperative, mutable code for something that plays to @ReasonML's strengths. #100DaysOfCode #ReasonML github.com/jbranchaud/sor…
Day 30: Lists in @ReasonML are linked-lists that can be pulled apart as first and rest -- this recursive function will peel a list apart until it finds the last. If the list is empty, it will raise with failwith. #100DaysOfCode #ReasonML
Day 31: @ReasonML's List module doesn't have a reduce function, so I decided to write my own. It works on lists of any type. Below are a couple usage examples. #100DaysOfCode #ReasonML
Day 32: Turns out that the @ReasonML ecosystem offers multiple ways to reduce a list. The built-in version is called fold_left and then Belt, which comes with bsb-native, has reduce. #100DaysOfCode #ReasonML
Day 33: Do the (Fisher-Yates) shuffle -- this tiny @ReasonML algorithm is a handy way to give any list a good mix so that the items end up in a random order. Using random ints and mutation for this one. #100DaysOfCode #ReasonML
Day 34: Yesterday's snippet used an undisclosed list printing function which I reveal to you here. With @ReasonML's support of currying, it is easy to self-document list enumeration code. #100DaysOfCode #ReasonML
Day 35: A re-implementation of the `tree` command in @ReasonML which recursively lists the contents of a directory. I still have some cleanup and output formatting to do, but it's a good start. #100DaysOfCode #ReasonML github.com/jbranchaud/tre…
Day 36: Added a couple updates to improve the tree printing logic. This really gives it that original `tree` command look and feel. #100DaysOfCode #ReasonML github.com/jbranchaud/tre…
Day 37: I started playing around with Reprocessing -- Processing meets @ReasonML. Here are some basic shapes drawn to an OpenGL canvas. #100DaysOfCode #ReasonML github.com/jbranchaud/sha…
Day 38: I wrote a little @ReasonML utility that converts a hex color (e.g. #B10DC9) into RGBA values (e.g. rgba(177, 13, 201, 255)). This is going to come in pretty handy as I continue to mess around with Reprocessing. #100DaysOfCode #ReasonML
Day 39: Playing a bit more with @ReasonML's Reprocessing -- I used my hex_to_rgba converter to translate @mrmrs_ clrs.cc and then render each as a circle. #100DaysOfCode #ReasonML github.com/jbranchaud/cir…
Day 40: I pulled in my implementation of the Fisher-Yates shuffle and some mouse press handling logic to randomize the order of the colored circles. #100DaysOfCode #ReasonML github.com/jbranchaud/cir…
Day 41: Found out about this thing called lerp (linear interpolation), so here are some circles gliding across the canvas. More Reprocessing with @ReasonML in this one. #100DaysOfCode #ReasonML github.com/jbranchaud/ler…
Here is the lerp function that uses various alpha values to transition from a start value to a finish value. #ReasonML

Read more on this here: en.wikipedia.org/wiki/Linear_in…
Day 42: I wanted to emphasize the differences in motion of each circle, so I added a mechanism to record and render all the previous circle positions.

Reprocessing is 💯! Check out the video. #100DaysOfCode #ReasonML github.com/jbranchaud/ler…
Day 43: @ReasonML types can be used to define the type signature of a function. This lerp function takes 3 float values and returns a float. Also of note, float operators are suffixed with a dot. #100DaysOfCode #ReasonML github.com/jbranchaud/ler…
Day 44: Bringing @ReasonML into a @Gatsby v2 project -- all it took was adding gatsby-plugin-reason as a plugin and including a bsconfig.json file. #100DaysOfCode #ReasonML gatsbyjs.org/packages/gatsb…
Day 45: Writing a HelloWorld component in @ReasonML, wrapping it for use in JS code, and then importing it into the index.js of a @gatsbyjs project. #100DaysOfCode #ReasonML
Day 46: Another basic Hello component in @ReasonML -- this one demonstrates how to configure the component to accept props from JS land. #100DaysOfCode #ReasonML
Day 47: This module wraps @Gatsby's Link component so that it can be used in a @ReasonML context. This requires defining the expected props. Note the bs directive for handling the reserve word 'to'. #100DaysOfCode #ReasonML
Day 48: Fetching data from the @rickandmortyapi and then parsing the resulting JSON using @ReasonML with help from bs-fetch and bs-json. #100DaysOfCode #ReasonML github.com/jbranchaud/gat…
Huge assists on this from @sharifsbeat with this detailed blog post and @myernore for helping me _reason_ through some of the tricky bits. medium.com/@sharifsbeat/f…
Day 49: Put together this simple @ReasonML string component as another alternative to declaring ReasonReact.string everywhere. See below for the before and after. #100DaysOfCode #ReasonML github.com/jbranchaud/gat…
This blog post by @iamlucasmreis has a very detailed and approachable explanation of how to get started with API fetching and JSON decoding in @ReasonML. \cc @MyerNore lucasmreis.github.io/blog/learning-…
Day 50: Taking advantage of module scoping to change a bunch of inline opens to a single explicit open, all within this Decode module. See the before and after examples below. #100DaysOfCode #ReasonML
Day 51: Giving @thangngoc89's sketch.sh a try. Here is an example of a code block that can be evaluated in the browser. #100DaysOfCode #ReasonML sketch.sh/s/tVm0ic3S5qiE…
Day 52: Decoding an additional JSON value from @rickandmortyapi to be able to display images of the characters. Add a little structure and styling. @ReasonML's strong typing at work. #100DaysOfCode #ReasonML
The facial expressions that the API creator picked for each of these characters is spot on.
Day 53: I'm adding some pagination controls for viewing more Rick and Morty characters. In order to correctly render unicode characters we need to wrap them in a JS Quoted String (reasonml.github.io/docs/en/string…). #100DaysOfCode #ReasonML
Day 54: Inspired by some of @sgrove's option helpers (gist.github.com/sgrove/600eeb9…), I put together this `exists` function for getting a boolean value based on the option resolving to None or Some. #100DaysOfCode #ReasonML
Day 55: Looking at just the first few Rick and Morty characters was getting boring, so I added some pagination logic. This involved additional API calls and click handlers. github.com/jbranchaud/gat… #100DaysOfCode #ReasonML
Day 56: Made some improvements to the pagination feature by using `ReasonReact.UpdateWithSideEffects`. This allows me to update state and have a callback with side-effects that gets `self` (allowing me to call `self.send`). #100DaysOfCode #ReasonML
Day 57: Figuring out how to use Dune, an OCaml/@ReasonML build system, for building Reason code into native executables. I did a writeup of a Hello World program on my TIL repo. #100DaysOfCode #ReasonML github.com/jbranchaud/til…
Day 58: Doing a bunch of research on the different ways to compile @ReasonML code to native executables. Options include:
- bsb-native (github.com/bsansouci/bsb-…)
- Dune (github.com/ocaml/dune)
- esy (github.com/esy/esy)
#100DaysOfCode #ReasonML
Day 59: Using esy and dune together to manage OCaml/@ReasonML dependencies and build native executables. Lwt and other deps are pulled in by esy and then esy builds it all with dune. #100DaysOfCode #ReasonML github.com/jbranchaud/esy…
Day 60: Doing some async programming with @ReasonML and Lwt. The bind function takes an async task and a callback to invoke when the async task resolves. #100DaysOfCode #ReasonML
Day 61: Nested callback logic can be eliminated from Lwt code by adding the lwt_ppx package to the project, instructing dune to use it as a preprocessing step, and then using `let%lwt`. It has an async/await kind of feel to it. #100DaysOfCode #ReasonML
Day 62: If you do prefer a callback-style syntax when using Lwt and @ReasonML, you can still tidy up the code a bit with Lwt.Infix. This module provides a pipe-like operator (>>=) for connecting a "promise" to a callback. #100DaysOfCode #ReasonML
Shoutout to @dysinger for pointing out this feature!
Day 63: With Esy+Dune I am able to pull in the dependencies for and build a program that uses Cohttp to fetch the @ReasonML website. The big gotcha was ensuring Cohttp was compiled with SSL. #100DaysOfCode #ReasonML
Day 64: Using lambdasoup with Cohttp to fetch and scrape a wikipedia page -- this @ReasonML snippet is able to grab all the Season 1 episode titles for Rick and Morty. #100DaysOfCode #ReasonML github.com/jbranchaud/scr…
Day 65: Continuing with lambdasoup in order to scrape all the episode descriptions. I then write them all to a file using @ReasonML's Unix module. #100DaysOfCode #ReasonML github.com/jbranchaud/scr…
Day 66: I’m looking for a more comprehensive String module for native @ReasonML development. The Jane Street Core String module has a ton of good additions to the stdlib. #100DaysOfCode #ReasonML ocaml.janestreet.com/ocaml-core/lat…
Day 67: This is a way of using @ReasonML's Unix module to write a list of strings to a new file. It gets a bit low-level once you have to work with the bytes and byte lengths. #100DaysOfCode #ReasonML
Day 68: This is another way of writing a list of strings to a new file. It is a bit less low-level by using @ReasonML's Pervasives module. #100DaysOfCode #ReasonML
Day 69: This is an imperative approach to reading non-blank lines from a file. It uses @ReasonML's Pervasives module. Switch Statements/Pattern Matching are so good for this kind of thing. #100DaysOfCode #ReasonML
Day 70: And a functional approach to reading non-blank lines from a file. This uses the same @ReasonML API as the previous approach, but ditches mutation in favor of a recursive function. #100DaysOfCode #ReasonML
Day 71: I created a WordCountList module (for lack of a better name) that can be fed a series of words and will track the count of each. The images show the source and an example of using it with @ReasonML's inline module opening syntax. #100DaysOfCode #ReasonML
Day 72: Adding an `of_list` function to the above module -- this follows a @ReasonML convention of making it easy to work with existing types, such as a list of strings. #100DaysOfCode #ReasonML
Day 73: Updating the `of_list` function from yesterday to handle the case where these strings contain other kinds of whitespace -- this involved moving to `Core.String.split_on_chars`. #100DaysOfCode #ReasonML
Day 74: Added a couple support functions to the WordCountList module I've been working on in order to simplify the above `of_list` function. @ReasonML's type system makes these kinds of refactorings much easier than they would otherwise be. #100DaysOfCode #ReasonML
Day 75: Decided to see what testing capabilities are available in the @ReasonML/@OCamlLang world -- I found the Alcotest library. Here is a proof-of-concept for using Alcotest in ReasonML with Dune+Esy. #100DaysOfCode #ReasonML
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to 🔥 Josh Branchaud 🕺🏼
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($3.00/month or $30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!