# Category Theory

Category theory is a way to abstract programming, enabling the creation of complex programs that are readable, extensible, and testable. It provides a mathematical abstraction for code.

#### category consist of type object and morphs

- morphs interpreted as a function or operation that transforms data from one form to another.

- object in functional programming might refer to a data structure that bundles together related information.

`f:a -> b // f is morphs and a is object`

morphs might refer to functions or transformations that take one input and produce a modified output without any internal state or side effects these types are known as pure functions.

# What is Pure functions

Pure functions are deterministic, meaning they always produce the same output given the same input, and they don't rely on or modify any external state.

# what is Composition

To form Relation between two morphs.

The practice of combining simpler functions to build more complex functions. It involves taking two or more functions and creating a new function by chaining them together, where the output of one function becomes the input of the next function.

for example in js/ts - map,filter,reducer

```
f:a->f:b->c
composition - gāf
```

Functional Style

# Rules of Category

1> Composition definition

2> Composition associative

3> Composition Identity

#### Composition Definition

If you have two functions composed one after another, it implies that there exists a third arrow starting from the first function and ending at the second function.

f:A -> B and g:B -> C then k = g * f,

where k:A -> C

composition k is defined as mapping elements from A to C by first applying function f to map elements from A to B and then applying function g to map the result from B to C.

#### Composition Associative

The order of the Composing function should not matter. Whether you first compose f and g than h or g and h and then f.

f: A -> B, g:B -> C and h:C -> D then,

(f * g) * h === f * (g * h)

it assures us that no matter which order we apply the compositions than final result will be the same.

#### Composition Identity

f:A -> A

It is a function that maps every element of a set

A to itself.

## Top comments (0)