# clark-fp

> Functional programming utilities

Latest version **0.5.11** (published 2024-05-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install clark-fp
pnpm add clark-fp
yarn add clark-fp
bun add clark-fp
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.11 |
| Published | 2024-05-09 |
| First published | 2024-04-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gideão Silva |
| Maintainers | gideaoms |
| Keywords | Javascript, Typescript, FP, Functional programming, ts-pattern, pattern matching, either, maybe |

## Links

- npm: https://www.npmjs.com/package/clark-fp
- Repository: https://github.com/gideaoms/clark-fp
- Homepage: https://github.com/gideaoms/clark-fp#readme
- Issues: https://github.com/gideaoms/clark-fp/issues
- npm.io page: https://npm.io/package/clark-fp

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.5.11 (latest) — 2024-05-09
- 0.5.10 — 2024-05-09
- 0.5.9 — 2024-05-04
- 0.5.8 — 2024-05-04
- 0.5.7 — 2024-05-03
- 0.5.6 — 2024-05-03
- 0.5.5 — 2024-05-03
- 0.5.4 — 2024-05-02
- 0.5.3 — 2024-05-02
- 0.5.2 — 2024-05-02
- 0.5.1 — 2024-05-02
- 0.5.0 — 2024-05-02
- 0.4.5 — 2024-05-02
- 0.4.4 — 2024-05-02
- 0.4.3 — 2024-05-02
- … 7 more at https://npm.io/package/clark-fp/versions

## README

# clark-fp
Introducing our lightweight library designed to enhance code reliability using functional programming techniques. Built to empower developers, it introduces features like either, option, tag, and match. Simplify error handling and promote predictability in your code with ease.

![clark-fp](https://github.com/gideaoms/clark-fp/assets/6031121/9329a915-7d8e-4595-9df8-b94aa0578daf)

## Install
```cmd
npm install clark-fp
```

## Examples

### Either
```ts
import { either } from "clark-fp";

function readFile(path: string) {
  try {
    const result = // ...read file here
    return either.Ok(result);
  } catch (err) {
    return either.Err(err);
  }
}

const result = readFile("file.txt");
if (either.isOk(result)) {
  console.log(`Error: ${result.value.message}`);
} else {
  console.log(result);
}
```

### Option
```ts
import { option } from "clark-fp";

function readFile(path: string) {
  try {
    const result = // ...read file here
    return option.Some(result)
  } catch (err) {
    return option.None
  }
}

const result = readFile("./file.txt");
if (option.isNone(result)) {
  console.log(`Error: file not found`);
} else {
  console.log(result);
}
```

### Match
This function was inspired by [ts-pattern](https://github.com/gvergnaud/ts-pattern), the difference is that this library is simpler in terms of pattern matching and you can return a value directly instead of having to create a arrow function
```ts
import { match } from "clark-fp";

const status = "active" as "active" | "inactive";

const result = match(status)
  .when("active", "You are active")
  .when("inactive", (status) => `You are not ${status}`)
  .exhaustive();

console.log(result);
```

### Tag
```ts
import { tag, either } from "clark-fp";

function readFile(path: string) {
  try {
    const result = // ...read file here
    return either.Ok(result);
  } catch (err) {
    return either.Err(err);
  }
}

const path = "file.txt";
const result = await readFile(path);
const msg = tag(result, {
  Ok: "The file was read successfully",
  Err: (err) => err.message,
});

console.log(msg);
```

---
_Source: https://npm.io/package/clark-fp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
