Photo by Levi Alvarez on Unsplash

Hello and welcome. I’m so happy to bring this to you today as I’ve been trying off and on to come up with what I think is an elegant solution to this problem for about a year now.

So let’s start with the obvious, Promises can and will fail. They often involve communication with another process that we don’t control, and because we don’t control the other process we can’t improve its reliability. Often our best course of action is to simply have some form of retry policy.

There are a few facts about promises that we’ll need to keep…


Photo by Devin Avery on Unsplash

It is common to think of a filter as a function from A -> boolean. Given a value of some type A, return a boolean. The filter function on the Array prototype works exactly this way. It takes a function and applies it to each item returning a new array with the items where the function returned true [1,2,3].filter(x => x < 2) returns [1] because 1 is the only value to satisfy the predicate (function that returns a boolean).

For in memory filtering this approach works well, but what would happen if we wanted to pass a complex filter…


This was written somewhere else, by someone who probably did a better job explaining it than I’m doing. But I can’t find that link, so here goes…

Photo by Olav Ahrens Røtne on Unsplash

In the common ways in which problems are deconstructed in OO and FP there are tradeoffs in the future extensibility of the program. Take the following two examples, in pseudo Haskell and C# respectively.

Haskell, FP approach

type Shape
= Square
| Circle
display :: Shape -> String
display Square = "Square"
display Circle = "Circle"
sides :: Shape -> Int
sides Square = 4
sides Circle = 1

C#, OO approach

interface IShape {
string Display();
int Sides()…


We want to be able to describe what it means to move our rover without caring whether the implementation is just in memory or there’s an actual rover millions of miles away reacting to our commands.

Photo by Jared Evans on Unsplash

I’ve wanted to play with Purescript for some time now but couldn’t decide on a project. I wanted something that was small enough to finish in a couple sittings but would still showcase some of the language features. That’s when I saw the following tweet:

The kata is quite simple: given a starting point, move around a 10 x 10 grid with Forward…


I can only imagine the face I made the first time someone referred to the type of an application. Coming from a Delphi, .NET, and web background at the time, I assumed the type of an application was Web vs Desktop vs Command Line. What I came to understand was that types can be used to model effects which can then determine what your application does.

“closeup photo of person's hand” by Daniel Jensen on Unsplash

The Zombie apocalypse of Async..Await

The first time I saw a hint of this sort of thing was when I first saw async..await in C# when Task came on the scene and it’s even more prevalent now with Promise


Photo by Stefan Steinbauer on Unsplash

Throughout my time as a software developer one of the things I’ve developed is the ability to identify and find an increasing amount of patterns. Some patterns are obvious while others have taken me years to stumble upon and then identify. In this article I’ll start with some imperative code and we’ll tease out a very common pattern.

As you can probably tell, this code finds the total age of all Persons in the people array. It makes use of a mutable variable totalAge and a for..of loop to achieve the effect. Chances are you’ve seen or even written…


“low light photography of stacked luggage” by Belinda Fewings on Unsplash

If you’ve programmed in virtually any mainstream language you might not have considered that there was anything wrong with returning void. I know I didn’t see what the issue was for a long time. In this post I want to hopefully show why returning void is almost always the wrong choice and how we can structure our programs to take advantage of the additional information this approach provides.

Some motivation

A tip came across my twitter feed suggesting that if you don’t need to return anything while iterating over an array you could use forEach instead of map.


“person plotting in map” by rawpixel on Unsplash

The process of string parsing comes up pretty frequently in development, but rarely do I stumble upon a solution I like as much as the one which I found today. My terms of success were straightforward: I wanted type safe parsing with the ability to compose Parsers while keeping the library’s api as simple as possible.

What is a Parser?

The first step was to define what a Parser is, which turns out to be quite simple.

So a Parser is any object with a run function that takes an input string and returns a ParserResult. The ParserResult then holds the parsed result…


Photo by Darren Bockman on Unsplash

In this post, we’ll look at several problem domains and see how we can model them with Abstract Algebra. While we’ll look at a few specific domains, the intent is to help you form an intuition for applying this approach to any problem domain.

Properties

Modeling with Abstract Algebra is all about finding the properties that our domain holds. In this case I’m using the term “properties” the same way someone talking about “Property Based Testing” is. The idea being that our specific values don’t matter as much as the properties that arise when viewing inputs and outputs to our domain…


“shallow focus photography of Rolls Royce emblem” by David Hellmann on Unsplash

When you have a query of some sort it implicitly has a result type associated with it. By using a Phantom Type we can include that type information with the query so that the result set is already typed.

In almost every application I write there’s a need to query data from another system, and for years I was choosing very poor abstractions to model these sorts of interactions. Here’s an example of how I would typically go about modeling a SQL query.

This seems to make sense, because a Query will typically have some sql and potentially some…

Reid Evans

Functional programmer, conference speaker, cofounder of Functional Knox Inc, principal consultant with ResultStack. @ReidNEvans

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store