-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from ritesh404/docs/update
Update and publish docs
- Loading branch information
Showing
13 changed files
with
697 additions
and
565 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ interface/* | |
*.js | ||
*.js.map | ||
.cursorrules | ||
site/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
# KudoJS Docs | ||
# KudoJS Documentation | ||
|
||
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. | ||
|
||
* See [Helper Functions](helper-functions.md) for documentation on all the methods in the kudoJS.* namespace. | ||
## Overview | ||
|
||
- [Helper Functions](helper-functions.md) - Documentation for all utility functions in the `kudoJS.*` namespace | ||
- [ADT Documentation](#kudojs-algebraic-data-types) - Detailed documentation for each ADT implementation | ||
|
||
### KudoJS Algebraic Data Types | ||
### Algebraic Data Types (ADTs) | ||
|
||
ADTs under the kudoJS.* namespace. All of the data types are compatible with the [Fantasy Land Specifications](https://github.com/fantasyland/). For the full documentation of each data type refer to the following: | ||
ADTs under the kudoJS.\* namespace. All of the data types are compatible with the [Fantasy Land Specifications](https://github.com/fantasyland/) | ||
|
||
* [`kudoJS.Pair`](pair.md) | ||
* [`kudoJS.Maybe`](maybe.md) | ||
* [`kudoJS.Either`](either.md) | ||
* [`kudoJS.Task`](task.md) | ||
* [`kudoJS.Reader`](reader.md) | ||
* [`kudoJS.State`](state.md) | ||
- [`kudoJS.Identity`](identity.md) - Type for handling pure values | ||
- [`kudoJS.Pair`](pair.md) - Tuple type for handling two values | ||
- [`kudoJS.Maybe`](maybe.md) - Type for handling nullable values safely | ||
- [`kudoJS.Either`](either.md) - Type for handling branching and error cases | ||
- [`kudoJS.Task`](task.md) - Type for handling asynchronous computations | ||
- [`kudoJS.Reader`](reader.md) - Type for handling dependency injection | ||
- [`kudoJS.State`](state.md) - Type for handling stateful computations | ||
|
||
### Summary | ||
## ADT Reference | ||
|
||
| ADT | Constructors | Static Methods | Instance Methods | | ||
| ------------- |:-------------:|:-----------------:| ----:| | ||
| `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` | | ||
|
||
--- | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,187 +1,204 @@ | ||
<a name="Either"></a> | ||
|
||
## 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` | ||
|
||
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. | ||
`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`. | ||
|
||
**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> | ||
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. | ||
|
||
* [Either](#Either) | ||
* [.of](#Either.of) | ||
* [.Right](#Either.Right) | ||
* [.Left](#Either.Left) | ||
* [.fromNullable](#Either.fromNullable) | ||
* [.withDefault](#Either.withDefault) | ||
* [.swap()](#Either.swap) | ||
* [.try(f)](#Either.try) | ||
* [.bimap(e, fl, fr)](#Either.bimap) | ||
* [.isLeft()](#Either.isLeft) | ||
* [.isRight()](#Either.isRight) | ||
* [.equals(n)](#Either.equals) | ||
* [.map(f)](#Either.map) | ||
* [.bimap(fl, fr)](#Either.bimap) | ||
* [.chain(f)](#Either.chain) | ||
* [.swap()](#Either.swap) | ||
* [.isLeft(e)](#Either.isLeft) | ||
* [.isRight(e)](#Either.isRight) | ||
* [.ap(j)](#Either.ap) | ||
* [.getValue()](#Either.getValue) | ||
**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> | ||
|
||
- [Either](#either) | ||
- [Either.of(v)](#eitherofv) | ||
- [Either.Right(v)](#eitherrightv) | ||
- [Either.Left(v)](#eitherleftv) | ||
- [Either.fromNullable(v)](#eitherfromnullablev) | ||
- [Either.withDefault(def, v)](#eitherwithdefaultdef-v) | ||
- [Either.swap()](#eitherswap) | ||
- [Either.try(f)](#eithertryf) | ||
- [Either.bimap(e, fl, fr)](#eitherbimape-fl-fr) | ||
- [Either.isLeft(e)](#eitherislefte) | ||
- [Either.isRight(e)](#eitherisrighte) | ||
- [Either.equals(n)](#eitherequalsn) | ||
- [Either.map(f)](#eithermapf) | ||
- [Either.bimap(fl, fr)](#eitherbimapfl-fr) | ||
- [Either.chain(f)](#eitherchainf) | ||
- [Either.swap()](#eitherswap-1) | ||
- [Either.isLeft()](#eitherisleft) | ||
- [Either.isRight()](#eitherisright) | ||
- [Either.ap(j)](#eitherapj) | ||
- [Either.getValue()](#eithergetvalue) | ||
|
||
<a name="Either.of"></a> | ||
|
||
### Either.of(v) | ||
Creates a Right Either | ||
|
||
Creates a **Right** `Either`. | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| v | <code>any</code> | Value | | ||
| Param | Type | Description | | ||
| ----- | ---------------- | ----------- | | ||
| v | <code>any</code> | Value | | ||
|
||
<a name="Either.Right"></a> | ||
|
||
### Either.Right(v) | ||
Creates a Right Either | ||
|
||
Creates a **Right** `Either`. | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| v | <code>any</code> | Value | | ||
| Param | Type | Description | | ||
| ----- | ---------------- | ----------- | | ||
| v | <code>any</code> | Value | | ||
|
||
<a name="Either.Left"></a> | ||
|
||
### Either.Left(v) | ||
Creates a Left Either | ||
|
||
Creates a **Left** `Either`. | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| v | <code>any</code> | Value | | ||
| Param | Type | Description | | ||
| ----- | ---------------- | ----------- | | ||
| v | <code>any</code> | Value | | ||
|
||
<a name="Either.fromNullable"></a> | ||
|
||
### 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 | | ||
| --- | --- | --- | | ||
| v | <code>any</code> | Value | | ||
| Param | Type | Description | | ||
| ----- | ---------------- | ----------- | | ||
| v | <code>any</code> | Value | | ||
|
||
<a name="Either.withDefault"></a> | ||
|
||
### 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. | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| f | <code>function</code> | A function that may throw an error | | ||
Executes the passed function that may throw and converts it to an `Either` type. | ||
|
||
| Param | Type | Description | | ||
| ----- | --------------------- | ---------------------------------- | | ||
| f | <code>function</code> | A function that may throw an error | | ||
|
||
<a name="Either.bimap"></a> | ||
|
||
### 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 | ||
|
||
| 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 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 | | ||
|
||
<a name="Either.isLeft"></a> | ||
|
||
### Either.isLeft(e) | ||
A static method that returns true if the passed Either is a Left | ||
|
||
Param | Type | Description | | ||
| --- | --- | --- | | ||
| e | <code>any</code> | Either type | | ||
A static method that returns `true` if the passed `Either` is a **Left**. | ||
|
||
| 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 | ||
|
||
Param | Type | Description | | ||
| --- | --- | --- | | ||
| e | <code>any</code> | Either type | | ||
A static method that returns `true` if the passed `Either` is a **Right**. | ||
|
||
| 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 | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| n | <code>any</code> | Any Value of Type Setoid | | ||
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` | | ||
|
||
<a name="Either.map"></a> | ||
|
||
### Either.map(f) | ||
Applies the passed function to the value of the current Either if it is a Just | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| f | <code>function</code> | Function | | ||
Applies the passed function to the value of the current `Either` if it is a **Right**. | ||
|
||
| Param | Type | Description | | ||
| ----- | --------------------- | ----------- | | ||
| f | <code>function</code> | Function | | ||
|
||
<a name="Either.bimap"></a> | ||
|
||
### Either.bimap(fl, fr) | ||
Apply 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 | | ||
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 | | ||
|
||
<a name="Either.chain"></a> | ||
|
||
### Either.chain(f) | ||
An instance method that can chain together many computations that return a Either type | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| f | <code>function</code> | Function that returns another Either | | ||
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` | | ||
|
||
<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 | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| j | <code>any</code> | Either with a function | | ||
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 | | ||
|
||
<a name="Either.getValue"></a> | ||
|
||
### Either.getValue() | ||
Get the value within the Either | ||
|
||
Gets the value inside the `Either`. |
Oops, something went wrong.