Skip to content

Commit

Permalink
chore: publish docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ritesh404 committed Dec 15, 2024
1 parent 678ea4a commit e9b32ff
Show file tree
Hide file tree
Showing 13 changed files with 415 additions and 324 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ interface/*
*.js
*.js.map
.cursorrules
site/*
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

KudoJS is a small utility library with a collection of popular Algebraic Data Types and Helper functions to help you write code in a functional programming style in Javascript.

[KudoJS Documentation](https://ritesh404.github.io/kudojs/)

### Installation

Install and save KudoJS as a dependency in your current project
Expand Down
18 changes: 9 additions & 9 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ ADTs under the kudoJS.\* namespace. All of the data types are compatible with th

## ADT Reference

| ADT | Constructors | Static Methods | Instance Methods |
| ----------------- | :------------------------------------------------------------: | :--------------------------------: | ----------------------------------------------------------------------------------------------: |
| `kudoJS.Identity` | `Identity`, `of` | | `equals`, `concat`,`ap`, `getValue`, `map`,`chain`, `toString` |
| `kudoJS.Pair` | `Pair`, `of` | | `equals`, `concat`, `fst`, `snd`, `ap`, `getValue`, `map`, `bimap`, `chain`, `swap`, `toString` |
| `kudoJS.Maybe` | `of`, `Just`, `Nothing`, `zero`, `fromNullable`, `withDefault` | `catMaybes`, `isNothing`, `isJust` | `equals`, `ap`, `alt`, `map`, `chain`, `toString`, `getValue`, `isNothing`, `isJust` |
| `kudoJS.Either` | `of`, `Left`, `Right`, `fromNullable`, `withDefault` | `try`, `isLeft`, `isRight` | `equals`, `ap`, `getValue`, `map`, `bimap`, `chain`, `swap`, `toString`, `isLeft`, `isRight` |
| `kudoJS.Task` | `Task`, `of`, `rejected` | | `fork`, `concat`, `ap`, `getValue`, `map`, `chain`, `toPromise`, `toString` |
| `kudoJS.Reader` | `Reader`, `of`, `ask` | | `runWith`, `ap`, `getValue`, `map`, `chain`, `toString` |
| `kudoJS.State` | `State`, `of`, `get`, `put` | | `runWith`, `execWith`, `evalWith`, `ap`, `getValue`, `map`, `chain`, `toString` |
| ADT | Constructors | Static Methods | Instance Methods |
| ---------- | :------------------------------------------------------------: | :--------------------------------: | ----------------------------------------------------------------------------------------------: |
| `Identity` | `Identity`, `of` | | `equals`, `concat`,`ap`, `getValue`, `map`,`chain`, `toString` |
| `Pair` | `Pair`, `of` | | `equals`, `concat`, `fst`, `snd`, `ap`, `getValue`, `map`, `bimap`, `chain`, `swap`, `toString` |
| `Maybe` | `of`, `Just`, `Nothing`, `zero`, `fromNullable`, `withDefault` | `catMaybes`, `isNothing`, `isJust` | `equals`, `ap`, `alt`, `map`, `chain`, `toString`, `getValue`, `isNothing`, `isJust` |
| `Either` | `of`, `Left`, `Right`, `fromNullable`, `withDefault` | `try`, `isLeft`, `isRight` | `equals`, `ap`, `getValue`, `map`, `bimap`, `chain`, `swap`, `toString`, `isLeft`, `isRight` |
| `Task` | `Task`, `of`, `rejected` | | `fork`, `concat`, `ap`, `getValue`, `map`, `chain`, `toPromise`, `toString` |
| `Reader` | `Reader`, `of`, `ask` | | `runWith`, `ap`, `getValue`, `map`, `chain`, `toString` |
| `State` | `State`, `of`, `get`, `put` | | `runWith`, `execWith`, `evalWith`, `ap`, `getValue`, `map`, `chain`, `toString` |

---
101 changes: 52 additions & 49 deletions docs/either.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Either

Either is a monad and can be used as a generic structure for a type with two possibilities, a Left a or a Right b. It represents the logical disjunction between `a` and `b`
`Either` is a monad and can be used as a generic structure for a type with two possibilities: a **Left a** or a **Right b**. It represents the logical disjunction between `a` and `b`.

A common use of this structure is to handle things like error handling and things that may fail and when you want to provide additional information on the failure. It is used to represent a value which is either correct or an error. As a convention the Left constructor is used to hold an error value and the Right constructor is used to hold a correct value. This sort of a structure forces handling of failures to be explicit, and avoids the problems associated with throwing exceptions.
A common use of this structure is to handle error cases and situations where a computation might fail, while also providing additional information about the failure. It is used to represent a value that is either correct or an error. By convention, the **Left** constructor is used to hold an error value, and the **Right** constructor is used to hold a correct value. This structure forces explicit handling of failures and avoids the problems associated with throwing exceptions.

**Implements:** <code>[BiFunctor](https://github.com/fantasyland/fantasy-land#bifunctor)</code>, <code>[Monad](https://github.com/fantasyland/fantasy-land#monad)</code>, <code>[Setoid](https://github.com/fantasyland/fantasy-land#setoid)</code>

Expand Down Expand Up @@ -33,7 +33,7 @@ A common use of this structure is to handle things like error handling and thing

### Either.of(v)

Creates a Right Either
Creates a **Right** `Either`.

| Param | Type | Description |
| ----- | ---------------- | ----------- |
Expand All @@ -43,7 +43,7 @@ Creates a Right Either

### Either.Right(v)

Creates a Right Either
Creates a **Right** `Either`.

| Param | Type | Description |
| ----- | ---------------- | ----------- |
Expand All @@ -53,7 +53,7 @@ Creates a Right Either

### Either.Left(v)

Creates a Left Either
Creates a **Left** `Either`.

| Param | Type | Description |
| ----- | ---------------- | ----------- |
Expand All @@ -63,7 +63,7 @@ Creates a Left Either

### Either.fromNullable(v)

Creates a Right if the value is not null or undefined else creates a Left
Creates a **Right** if the value is not `null` or `undefined`; otherwise, creates a **Left**.

| Param | Type | Description |
| ----- | ---------------- | ----------- |
Expand All @@ -73,24 +73,24 @@ Creates a Right if the value is not null or undefined else creates a Left

### Either.withDefault(def, v)

Creates a Right if the value v is not null or undefined else creates a Right with the default value def
Creates a **Right** if the value `v` is not `null` or `undefined`; otherwise, creates a **Right** with the default value `def`.

| Param | Type | Description |
| ----- | ---------------- | ----------- |
| def | <code>any</code> | Value |
| v | <code>any</code> | Value |
| Param | Type | Description |
| ----- | ---------------- | ------------- |
| def | <code>any</code> | Default value |
| v | <code>any</code> | Value |

<a name="Either.swap"></a>

### Either.swap()

Swap the Left and Right elements of the current Either
Swaps the **Left** and **Right** elements of the current `Either`.

<a name="Either.try"></a>

### Either.try(f)

- Executes the passed function that may throw and converts it to an Either type.
Executes the passed function that may throw and converts it to an `Either` type.

| Param | Type | Description |
| ----- | --------------------- | ---------------------------------- |
Expand All @@ -100,49 +100,49 @@ Swap the Left and Right elements of the current Either

### Either.bimap(e, fl, fr)

A static method that applies fl to the Left element or fr to the Right element of the current Either
A static method that applies `fl` to the **Left** element or `fr` to the **Right** element of the current `Either`.

| Param | Type | Description |
| ----- | --------------------- | ------------------------------------------- |
| e | <code>any</code> | Either type |
| fl | <code>function</code> | Function to be applied on the Left element |
| fr | <code>function</code> | Function to be applied on the Right element |
| Param | Type | Description |
| ----- | --------------------- | ----------------------------------------------- |
| e | <code>any</code> | `Either` type |
| fl | <code>function</code> | Function to be applied on the **Left** element |
| fr | <code>function</code> | Function to be applied on the **Right** element |

<a name="Either.isLeft"></a>

### Either.isLeft(e)

A static method that returns true if the passed Either is a Left
A static method that returns `true` if the passed `Either` is a **Left**.

| Param | Type | Description |
| ----- | ---------------- | ----------- |
| e | <code>any</code> | Either type |
| Param | Type | Description |
| ----- | ---------------- | ------------- |
| e | <code>any</code> | `Either` type |

<a name="Either.isRight"></a>

### Either.isRight(e)

A static method that returns true if the passed Either is a Right
A static method that returns `true` if the passed `Either` is a **Right**.

| Param | Type | Description |
| ----- | ---------------- | ----------- |
| e | <code>any</code> | Either type |
| Param | Type | Description |
| ----- | ---------------- | ------------- |
| e | <code>any</code> | `Either` type |

<a name="Either.equals"></a>

### Either.equals(n)

Returns true if the current and the passed element are of Either type with the same value
Returns `true` if the current and the passed element are of `Either` type with the same value.

| Param | Type | Description |
| ----- | ---------------- | ------------------------ |
| n | <code>any</code> | Any Value of Type Setoid |
| Param | Type | Description |
| ----- | ---------------- | -------------------------- |
| n | <code>any</code> | Any value of type `Setoid` |

<a name="Either.map"></a>

### Either.map(f)

Applies the passed function to the value of the current Either if it is a Just
Applies the passed function to the value of the current `Either` if it is a **Right**.

| Param | Type | Description |
| ----- | --------------------- | ----------- |
Expand All @@ -152,50 +152,53 @@ Applies the passed function to the value of the current Either if it is a Just

### Either.bimap(fl, fr)

Apply fl to the Left element or fr to the Right element of the current Either
Applies `fl` to the **Left** element or `fr` to the **Right** element of the current `Either`.

| Param | Type | Description |
| ----- | --------------------- | ------------------------------------------- |
| fl | <code>function</code> | Function to be applied on the Left element |
| fr | <code>function</code> | Function to be applied on the Right element |
| Param | Type | Description |
| ----- | --------------------- | ----------------------------------------------- |
| fl | <code>function</code> | Function to be applied on the **Left** element |
| fr | <code>function</code> | Function to be applied on the **Right** element |

<a name="Either.chain"></a>

### Either.chain(f)

An instance method that can chain together many computations that return a Either type
An instance method that can chain together many computations that return an `Either` type.

| Param | Type | Description |
| ----- | --------------------- | ------------------------------------ |
| f | <code>function</code> | Function that returns another Either |
| Param | Type | Description |
| ----- | --------------------- | -------------------------------------- |
| f | <code>function</code> | Function that returns another `Either` |

<a name="Either.swap"></a>

### Either.swap()

Swap the Left and Right elements of the current Either
Swaps the **Left** and **Right** elements of the current `Either`.

<a name="Either.isLeft"></a>

### Either.isLeft()

An instance method that returns true if the current Either is a Left
An instance method that returns `true` if the current `Either` is a **Left**.

<a name="Either.isRight"></a>

### Either.isRight()

An instance method that returns true if the current Either is a Right
An instance method that returns `true` if the current `Either` is a **Right**.

<a name="Either.ap"></a>

### Either.ap(j)

Applies the function inside the passed Either to the current Either if it is a Right
Applies the function inside the passed `Either` to the current `Either` if it is a **Right**.

| Param | Type | Description |
| ----- | ---------------- | ---------------------- |
| j | <code>any</code> | Either with a function |
| Param | Type | Description |
| ----- | ---------------- | ------------------------ |
| j | <code>any</code> | `Either` with a function |

<a name="Either.getValue"></a>

### Either.getValue()

Get the value within the Either
Gets the value inside the `Either`.
Loading

0 comments on commit e9b32ff

Please sign in to comment.