https://github.com/olaven/fun
Util library for functional programming in Deno
https://github.com/olaven/fun
deno functional-programming library typescript
Last synced: 8 months ago
JSON representation
Util library for functional programming in Deno
- Host: GitHub
- URL: https://github.com/olaven/fun
- Owner: olaven
- License: lgpl-3.0
- Created: 2020-05-09T09:31:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-23T13:35:46.000Z (over 5 years ago)
- Last Synced: 2025-01-27T11:16:34.696Z (10 months ago)
- Topics: deno, functional-programming, library, typescript
- Language: TypeScript
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Fun  [](https://doc.deno.land/https/raw.githubusercontent.com/olaven/fun/master/mod.ts) [](https://codebeat.co/projects/github-com-olaven-fun-master)
Tiny utility library for functional programming in Deno/Deno
## About
This is a learning project I created because I wanted to understand some
concepts in functional programming. Use the library if you want, but keep
in mind that it is not meant to be anything serious.
## Getting started
One function is exported: `fun`. You pass a value to it.
In return, it gives you functions to apply to your value.
These functions are:
`map`, `apply`, `run` and `get`.
* `map` -> transform to new type
* `apply` -> transform within same type
* `run` -> run arbitrary code
* `get` -> get your value back
See the example below:
```typescript
// Node
// - npm install fun-node
import { fun } from "fun-node"
// Deno
import { fun } from "https://denopkg.com/olaven/fun"
interface Person { name: string, salary: number }
const person: Person = { name: "joe", salary: 100 };
const format_salary = (person: Person) =>
fun(person)
.map(person => person.salary)
.map(salary => salary.toString())
.apply(salary => `${salary},-`)
.get();
//prints 100,-
console.log(format_salary(person));
```