More than 14 years’ experience as full stack developer and Software Architect .https://leanpub.com/u/dimitrispapadim

This is an article about functional Recursion on the Array data structure.

This article was inspired by the article “Functional JS with ES6 — Recursive Patterns” but here we are going to take a road that is more profound and has to do that the algebraic definition of a List is `List = 1+a*List`

This says that the list is either the empty list

[]or a concatenation of an elementaand a smaller list .

First we can write the following patternMatch method that allow us to separate the different parts of the list

The pattern object…

One can argue that composing functions is the most important idea in programming and functional programming in particular. The idea of compositionality is of monumental importance in human thinking. Creating systems by composing smaller systems that are easier to implement and design can be found in all levels of programming. Staring from the Syntax of the language, to Design patterns, architectural patterns, larger System design etc.

In this section we are going to take a brief look at one of the most basic ones; Function composition.

Functional composition is in the heart of many object-oriented best practices. Here we will see an idiomatic expression of the Decorator design pattern, which is one of the most used object-oriented design patterns from Gang of Four.

Let start with simple example where we have a `ProductA `

, and we can decorate it with Packaging. Adding a packaging would affect the price, but we want to treat a product and a packaged product interchangeably in our code. The decorator pattern allows us to do just that by unifying both `ProductA `

and Packaging under a common in interface :

github repo : https://github.com/dimitris-papadimitriou-chr/FunctionalJsWithCategories/blob/master/monads/state-example-1/demo.js

This is a short article on how to create a game loop using the State monad. Unfortunately i am not going to cover the theory of State monad in this article but hopefully i would do this in a subsequent article.

using the State we can pass a state along with a value. We are going to use this to build a simple loop. It’s a simple string parsing algorithm. This simple game is an haskell example and goes like this :

Passes a string of dictionary {a,b,c}

Game is to produce a number from the string.

By…

Functors are closed under composition. This means that we should be able to construct a well-behaved `map`

method for the composition.

**Functors are closed under composition**. The term closed means that if we have two functors and we compose them (have a functor-in-a-functor situation like `Maybe<Id<>>`

or `Maybe<Array<>>`

, `Array<Array<>>`

etc), the resulting structure is also a functor.

This means that we should be able to construct a well-behaved `map`

method for the composition, using only the `map`

methods of the composing functors and nothing more.

Let us examine some specific cases. We will start with the `Id<Array<>>`

case. This is…

This article wants to intergrate the Folktale.js Maybe type in a React.js application

We are going to use the **Maybe type** from a Functional Library called Folktale.js. Folktale is probably the 3rd most popular Functional library (after Rambda and Senctuary.js)

If you are not familiar with **the maybe functor **read the previous article :

Folktale provides a Maybe Type with the two Cases named `Just`

and `Nothing`

. Other that that we have a `map`

method and a pattern matching method called `matchWith`

`Maybe.matchWith({`

Just: ({ value }) => _,

Nothing: () => _

});

The core example use…

Source Code .NET Fiddle : Maybe Monad Example C# 8.0 Pattern Matching

To be honest i didn't like the **pattern matching **feature the first time i show it. But i rewrote some sample functional code and i can say i might be a fan.

if you are not familiar with **pattern matching** read the previous article :

this article revises the Maybe monad seen previously

We will rewrite Maybe using C# 8.0 pattern matching

this is the initial

and now we can just simply replace it with

placing the map definition in the base class

`public abstract class…`

What is pattern matching ? Lets say that you have a simple hierarchy of shapes

Now if i make an assignment to a `Shape `

variable . **I can assign either a rectangle or a circle. **Here i will go with the rectangle

**Shape **shape = new **Rectangle **{ Width = 100, Height = 100, };

How can you find out during runtime what kind of shape did i put in ?

**This is the underling problem that pattern matching wants to solve.** We will see how C# 8.0 …

**Source**: https://codesandbox.io/s/parenthesis-balancing-usingmonoids-8ktvs

The Parenthesis Balancing problem is a classic problem that says :

Given an expression string exp, write a program to examine whether the pairs and the orders of “(“, “)” are correct in exp.

so this `(()()()())`

is balanced but this one `()))`

is not

in this article we are going to solve this in a functional manner using Typescript and the monoids from the previous article.

we are going to define a simple balance type that will hold the number of the left end right values.

this amazingly forms a monoid. Since we can concatenate two Balance…

“Alternatively, the fundamental notion of category theory is that of a Monoid”

— Categories for the Working Mathematician

Monoids are one of those profound ideas that are easy to understand and are everywhere. Monoids belong to the category of Algebras. There are a couple of very important ways to organize different structures that appear in functional programming. Algebras is one of them. Fantasy land has some of the most important algebras in its specification.

Wikipedia says a **monoid** is an algebraic structure with a single associative binary operation and an identity element. …