👊 First post for 2021!

Recently I decided to adopt fp-ts lib on a side project.

What is F p-ts ?

It’s a library that provides abstractions from typed functional languages that makes it easy to apply functional patterns when developing in TypeScript.

My motivation in adopting fp-ts was:

  • I’ve been charmed by languages such Haskell and Rust and wanted to use some familiar ADTs in the code (Option/Maybe, Just/Some, Either/Result, None).
  • I liked the Error handling approach.
  • I wanted to figure out if it can really improve my typescript projects while enjoying the functional style.

An easy kickstart

I’ve been reading the  fp-ts docs and posts for a while so what was left is to pick a simple side project code, generalise it a bit and start using fp-ts :)

I picked a simple procedure I have that fetches data I manage in google-sheets tables as follows:

  • Read sheet credentials from private local file
  • Authenticate
  • run fetchTables which fetches all tables in parallel (each table has its own route)

Note: following recipes are super useful 📓

Let’s review the fetchTable function sig:

function fetchTable<T>(sheets: Sheets, range: any, spreadsheetId: any): Promise<T> 

#javascript #typescript #software-development

fp-ts in action
1.10 GEEK