1591274700
This will be a series with a few articles in which I attempt to explain and show the use cases of some functional programming patterns.
We will work with TypeScript and use the functional programming library fp-ts. The examples and explanations are inspired by the great article series by the author of fp-ts.
#programming #typescript #javascript #functional-programming #software-development
1591274700
This will be a series with a few articles in which I attempt to explain and show the use cases of some functional programming patterns.
We will work with TypeScript and use the functional programming library fp-ts. The examples and explanations are inspired by the great article series by the author of fp-ts.
#programming #typescript #javascript #functional-programming #software-development
1594971540
This will be a series with a few articles, where I attempt to explain and show the use cases of some functional programming patterns.
We will work with TypeScript and use the functional programming library fp-ts. The examples and explanations are inspired by the great article series from the author of fp-ts
.
This is Part 7 of our series, and this article is about the Monad type class
. We will explore what Monads
are and what we can use them for.
So far we have seen how we can use map()
from the Functor type class
to lift pure unary
functions to the Functor
“world” and how we can use ap()
from the Apply type class
to lift pure n-ary
functions.
Functors
allow us to lift functions like (a: A) => B
.
Apply
allows us to lift functions like (a: A) => (b: B) => C
.
But what if we have a function like (a: A) => M<B>
(M
is a placeholder for an effect
, e.g., Option
or Array
)? If we were to use this function with map()
, we would end up with a nested context: M<M<B>>
.
#software-development #functional-programming #typescript #programming #javascript
1596645240
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.
“Alternatively, the fundamental notion of category theory is that of a Monoid”
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
1596300660
For those interested in functional programming, I’ll talk about monoids and why they’re very important to understand ahead of time.
Don’t get confused: This isn’t monad — it’s monoid. I’m pretty sure you already know of monoids and you use them almost every day — you just didn’t know the term for them.
This is a series on functional programming, so you might not understand what this article is going to talk about if you haven’t read the previous posts.
Let’s assume there’s a function named identity
that takes A
and returns A
.
const identity: <A>(a: A): A => a;
interface Student {
name: string;
age: number;
}
identity<number>(3) // 3
identity<string>('hello') // hello
identity<Student>({
name: 'Bincent',
age: 5
}); // { name: 'Bincent', age: 5 }
In functional programming, this useless function (seems useless) is an important factor for many other concepts (such as monoids) that we’re about to talk about.
Basically, a monoid is a set of elements that holds the rules of the semigroup and the identity-element rule.
If S
is a set of elements, a
is a member of S
, and ·
is a proper binary operation, a·e = e·a ∈ S
must be satisfied to be a monoid.
Identity: a ∈ S, a·e = e·a = a ∈ S
Some documentation calls this using the number 1 and the any alphabet in subscript — for example, 1x referring to the identity on the variable x. Or some documentation uses just a single alphabet letter, such as i or e.
That’s all there is to know about monoids, let’s practice with some simple examples.
#typescript #programming #functional-programming #javascript #coding #function
1602291900
Today I am going to talk about how to design Pure Function and help you understand the benefits of pure function.
Nowadays Functional Programming is getting a lot of attention due to the advantages it offers like parallelism, easier testing, _predictability _ and many others.
Pure functions is a concept mainly used in functional programming languages but it can be applied in any programming paradigm
Pure functions can be defined as
#functional-programming #lambda-function #functor #kotlin #programming #functional-components #coding #coding-skills