Skip to main content

Command Palette

Search for a command to run...

JavaScript is too hard. So I'm pivoting... into a cooking blog!

Published
3 min read
JavaScript is too hard. So I'm pivoting... into a cooking blog!
J

I like programming and learning about stuff I find interesting. Particularly interested in functional programming and typing systems.

I have a background in Cognitive Science/Psychology and Mathematics. Sadly halted due to physical and mental health issues arising from getting Covid. Which unfortunately hit me quite hard back on 2020. I'm still dealing with some sequels so I would prefer working from home.

I find it fun trying to find insights that cut across disciplines. I tend to favor the "theoretical" side of things. But I also try to get as much hands-on experience as possible.

I am writing a blog. Trying to share what I learn, and that others might find useful. I try to focus on the unique things I can bring to the table. Hoping to add value to the life of other developers. I always have a thousand ideas racing through my mind, so I don't have any trouble coming up with ideas on what to write. If any, I have a hard time cutting down on the number of things I want to write about :D

On a personal note. I have always been quite solitary and introverted. But I don't think I'm shy. I love videogames and started programming because I wanted to make my own.

Ok, here's the thing. I suck at coding. And I don't really like frontend. I have no industry experience.

And let's not kid ourselves, the only job title I actually will accept is that of Senior Fullstack Cloud Serverless Architect, or something.

So, after minutes of soul searching, I clinched a new goal. I flailed my arms up in the air, and with a dry gulp I sighed "F*ck it! I'm starting a cooking blog"

The obligatory tedious life story nobody cares about. In Every. Single. Cooking. Blog.

... Let's just agree that neither you want to read this, nor I want to write it. Moving on...

A recipe for fried eggs. (Because that's the only thing I can cook)

Let's start by importing and initializing our eggs

import {CreateEgg, Egg} from "./modules/Egg.js"

const eggs : Array<Egg> = CreateEgg(2)

You may note that I hard coded the number of eggs, which is not really a good idea. But this is a cooking blog! Quit expecting me to adopt good engineering practices! >:(

Moving on, we will also need some utility methods. The kitchen.js library is really simple to use, and very powerful if you take the time to dive into the docs.

To install it just run npm install kitchen.js. As we will use TypeScript for this tutorial, we will also need to grab the types with npm install @types/kitchen.js

import {Pan} from "kitchen.js"

const pan = new Pan(eggs.map(e => e.break()))

The constructor for the Pan object takes an array of cookable objects. Luckily it can cast our Egg object as a cookable with no extra work on our part. Given that it implements the cookable interface. One of the really nice things about TypeScript :D

The Egg class has a really convenient break() method that returns the egg already broken, saving you hours of tedious manual work. Also, we want to pass the already broken eggs into the pan constructor. Obviously.

Before we cook the eggs, note that the cook() method of Pan gives us the option to pass a callback to taste for salt. (There is a Promise version of this, but for simplicity we will stick to callbacks)


import {Taste, AddSalt} from "Kitchen.js"

pan.cook((t) => {
  if (t < Taste.good) {
    AddSalt(1)
  }
})

Note that AddSalt() takes the amount of salt in grams. Be careful! Also, Kitchen.js will take care of checking for salt at appropriate times, so you don't need to worry about it.

Finally, we can think of a way of serving and eating our eggs.


import {Plate} from "Kitchen.js"

const plate = new Plate(pan.serve())

plate.eat()

Again, kitchen.js is really nice because the pan object works seamlessly with Plate. Thats because Pan.serve() returns the pan’s contents wrapped in a cooked monad, which Plate expects.

Epilogue.

That was fun!

:D

S

Interesting! Cooking with JS ingredients, the dish is going to be tasty and so will be the its garnishing.

10

Writing Everyday!

Part 5 of 22

I want to make it a habit to write daily. So I will challenge myself to write *something*, everyday. Lower your expectations...

Up next

I was featured again!

I want to share some of the joy :D