Functors in Functional Programming


1. Overview

In this tutorial, we’ll take a look at Functor type class in Cats. The idea of Functor is “something that can be mapped over”, we’ll see what is actually mapped and how. In functional programming, Functors come into play when we have types or values wrapped inside contexts or containers. We don’t have to know any of the implementation details of those contexts or containers themselves.

2. SBT Dependencies

To start, let’s add the Cats library to our dependencies :

Functional Programming in JavaScript

JavaScript (and its ecosystem) is a language that’s evolving really fast. New libraries and frameworks appear at a frantic pace, offering new architectures and functionalities. In past articles, we’ve seen what TypeScript has in store for us as well as how to easily migrate from an old project to this JS Superset. Today’s article will be slightly different: this time, I’d like to show a couple of examples about how we can apply Functional Programming in JavaScript.

To that end, we’ll use Ramda-fantasy, a library of powerful abstractions offering a big set of Monads, and another library called Ramda, which will help us build functional pipelines and achieve immutability. Before we get started, though, a reminder: these aren’t the only libraries that offer these functionalities; search long enough and you can easily find perfectly valid alternatives. 

Code Organization in Functional Programming vs. Object Oriented Programming

Introduction

A co-worker asked about code organization in Functional Programming. He's working with a bunch of Java developers in Node for a single AWS Lambda, and they're using the same style of classes, various design patterns, and other Object Oriented Programming ways of organizing code. He wondered if they used Functional Programming via just pure functions, how would they organize it?

The OOP Way

If there is one thing I've learned about code organization, it's that everyone does it differently. The only accepted practice that seems to have any corroboration across languages is having a public interface for testing reasons. A public interface is anything that abstracts a lot of code that deals with internal details. It could be a public method for classes, a Facade or Factory design pattern, or functions from a module. All three will utilize many internal functions, but will only expose one function to use them. This can sometimes ensure as you add things and fix bugs, the consumers don't have to change their code when they update to your latest code. Side effects can still negatively affect this.