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.

Monoids in TypeScript

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

medium.com

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 objects and get a new balance.

#typescript #functional-programming #functional #javascript #monoids #function

Parenthesis Balancing using Monoids in TypeScript
2.00 GEEK