PureScript Async FFI

I recently posted about using Aff for asynchronous effects in PureScript. In this follow-up post, I’m going to discuss using JavaScript FFI in conjuction with Aff. Aff and FFI PureScript gives us very nice FFI utilities to call JavaScript code. Aff provides a function called fromEffectFnAff that lets us turn asynchronous JavaScript behavior into an Aff in our PureScript code. Let’s create an example that reads a file from the file system using FFI....

January 4, 2020 · Drew Olson

Asynchronous PureScript

One of my favorite features of PureScript is its ability to work with asynchronous effects. While learning the language, I struggled to find any beginner material that introduced the relevant topics and included small examples. This post hopes to fill that gap. Getting Started with Aff PureScript’s built-in type for effects is called Effect. However, this type represents synchronous effects. This means if we want expose asynchronous APIs to our users using Effect, we’re stuck with the callback-style....

December 17, 2019 · Drew Olson

Laziness in PureScript

I’ve been learning PureScript for the past few months and really enjoying it. PureScript is a Haskell dervied language that compiles to JavaScript. You can target node for the backend or the browser for frontend code. One of my favorite features of PureScript is its fantastic interop with JavaScript. This makes the language very pragmatic – though it has a large ecosystem of native packages, anything that’s missing can easily be handled with an existing npm package and interop....

June 19, 2019 · Drew Olson

Go Dependency Injection with Wire

Several months ago I wrote a blog post about dependency injection in go. In the time since that post was written, Google has released a fantastic new dependency injection container for go called wire. I much prefer wire to other containers in the go ecosystem. This post will explain why. A (Very) Brief Primer on Dependency Injection Dependency injection (DI) is a style of writing code such that the dependencies of a particular object (or, in go, a struct) are provided at the time the object is initialized....

April 7, 2019 · Drew Olson

Concurrent Ruby with Tasks

Yes, you read the title correctly. And yes, ruby still has a GIL. However, ruby has long been able to support concurrency for IO-bound calls. Ruby will not block the current thread if it is waiting on IO. In practice, this means that many of our ruby programs (like web applications) can use ruby’s threads to concurrently serve multiple requests. Working directly with ruby’s threading primitives can be complicated. This is a problem that the concurent-ruby library aims to solve....

October 29, 2018 · Drew Olson

So You Bought a Pixelbook

Initial Setup First, follow the Quickstart instructions here. You now have two things set up – a VM called termina and a container inside of that VM called penguin. This VM and container are “special” – files within penguin are accessible via the Files app and any GUI applications installed inside of penguin will be accessible via the launcher. Other than that, penguin is just a regular debian stretch LXC container....

June 16, 2018 · Drew Olson

Lazy Providers in Dig

If you haven’t yet read my previous post on depedency injection in Go, please do so first. This post describes a simple technique to make dig’s DI container even more powerful. All values provided by dig’s container are singletons. The provider is called the first time the value is required and the result is cached. All subsequent providers that depend on this value used the cached result. This behavior is usually very desireable but there are times when we want a fresh value to be produced by the container....

May 25, 2018 · Drew Olson

Dependency Injection in Go

Update - you should probably read my more recent post about dependency injection with wire. I recently built a small project in Go. I’ve been working with Java for the past few years and was immediately struck by the lack of momentum behind Dependency Injection (DI) in the Go ecosystem. I decided to try building my project using Uber’s dig library and was very impressed. I found that DI helped solve a lot of problems I had encountered in my previous Go applications – overuse of the init function, abuse of globals and complicated application setup....

May 15, 2018 · Drew Olson

Promises as Values

I was recently working on a small JavaScript project in which I needed to perform several asynchronous operations sequentially. I had a collection of images on a page and I needed to fade each of them out one at a time. I ended up with a nice technique using Promises. Let’s suppose we have a function that fades out an image given a selector and a duration (I was using jQuery, but the details don’t matter)....

July 13, 2017 · Drew Olson

Elixir's Secret Weapon

I recently began using a new(ish) feature of Elixir that completely transformed the way I build programs. I’m talking about the special form with. It can feel unfamiliar at first, but it is extremely powerful and flexible. This article will explain how with works and how it can be used to make your code more robust to errors. First, though, let’s look at the problem with is trying to solve....

May 12, 2017 · Drew Olson