This repository has been archived by the owner on May 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tomasz Gałkowski
committed
Jul 17, 2019
0 parents
commit e0f95ae
Showing
30 changed files
with
601 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*.ts] | ||
indent_style = space | ||
indent_size = 4 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# editors | ||
.vscode | ||
.idea | ||
|
||
# secrets | ||
.env |
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as | ||
contributors and maintainers pledge to making participation in our project and | ||
our community a harassment-free experience for everyone, regardless of age, body | ||
size, disability, ethnicity, sex characteristics, gender identity and expression, | ||
level of experience, education, socio-economic status, nationality, personal | ||
appearance, race, religion, or sexual identity and orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment | ||
include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable | ||
behavior and are expected to take appropriate and fair corrective action in | ||
response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, wiki edits, issues, and other contributions | ||
that are not aligned to this Code of Conduct, or to ban temporarily or | ||
permanently any contributor for other behaviors that they deem inappropriate, | ||
threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces | ||
when an individual is representing the project or its community. Examples of | ||
representing a project or community include using an official project e-mail | ||
address, posting via an official social media account, or acting as an appointed | ||
representative at an online or offline event. Representation of a project may be | ||
further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by contacting the project team at [email protected]. All | ||
complaints will be reviewed and investigated and will result in a response that | ||
is deemed necessary and appropriate to the circumstances. The project team is | ||
obligated to maintain confidentiality with regard to the reporter of an incident. | ||
Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good | ||
faith may face temporary or permanent repercussions as determined by other | ||
members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||
|
||
[homepage]: https://www.contributor-covenant.org | ||
|
||
For answers to common questions about this code of conduct, see | ||
https://www.contributor-covenant.org/faq |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Contributing | ||
Thank you for thinking about contributing to denofun! | ||
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. | ||
|
||
Please note we have a code of conduct, please follow it in all your interactions with the project. | ||
|
||
## Pull Request Process | ||
1. You Pull Request has to be zero-dependency excluding deno_std. | ||
2. Update README.md with required documenation. | ||
3. Update CHANGELOG.md with your proposed changes. | ||
4. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is SemVer. | ||
5. Your PR will be reviewed and merged by the repository's owner. | ||
|
||
Thanks! |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Tomasz Gałkowski | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test: | ||
deno --importmap=src/import_map.json src/test.ts |
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 |
---|---|---|
@@ -0,0 +1,174 @@ | ||
# denofun | ||
Small utility library for [Deno](https://deno.land) containing functions, monads and other fun stuff. | ||
|
||
<image src="https://media.giphy.com/media/XOXdQszYm4I3m/giphy.gif" width="480" height="360"> | ||
|
||
## Documentation | ||
Code samples assume [import map](https://deno.land/manual.html#importmaps) is configured like this (URL is still WIP, `denofun` like Deno is still under heavy development). | ||
|
||
``` | ||
{ | ||
"imports": { | ||
"std/": "https://deno.land/std/", | ||
"denofun/": "https://raw.githubusercontent.com/galkowskit/denofun/master/" | ||
} | ||
} | ||
``` | ||
|
||
### compose | ||
|
||
```typescript | ||
import compose from "denofun/lib/compose.ts"; | ||
|
||
function greet(name: string) { | ||
return `hello, ${name}!`; | ||
} | ||
|
||
function makeLoud(x) { | ||
return x.toUpperCase(); | ||
} | ||
|
||
const greetLoudly = compose(makeLoud, greet); | ||
|
||
greetLoudly('world'); // => HELLO, WORLD! | ||
``` | ||
|
||
### curry | ||
|
||
```typescript | ||
import curry from "denofun/lib/curry.ts"; | ||
|
||
const greet = (name: string, age: number) => `hello, I'm Tomasz and I'm 26 years old`; | ||
greet("Tomasz", 26); // => hello, I'm Tomasz and I'm 26 years old | ||
|
||
const curriedGreet = curry(greet); | ||
curriedGreet("Tomasz")(26) // => hello, I'm Tomasz and I'm 26 years old | ||
|
||
// === | ||
|
||
const cars = [ | ||
{ make: 'Alfa Romeo', model: 'Giulia' }, | ||
{ make: 'Alfa Romeo', model: 'Stelvio' }, | ||
{ make: 'Ford', model: 'Mustang '}, | ||
{ make: 'Ford', model: 'Focus '}, | ||
{ make: 'Toyota', model: 'Mirai' }, | ||
{ make: 'Toyota', model: 'Yaris' }, | ||
{ make: 'Toyota', model: 'Supra' }, | ||
]; | ||
|
||
const filterCarsByMake = curry((make: string, car) => car.make === make); | ||
const filterAlfas = filterCarsByMake('Alfa Romeo'); | ||
cars.filter(filterAlfas); // => [ { make: "Alfa Romeo", model: "Giulia" }, { make: "Alfa Romeo", model: "Stelvio" } ] | ||
``` | ||
|
||
### filter | ||
|
||
```typescript | ||
import filter from "denofun/lib/filter.ts"; | ||
|
||
const cars = [ | ||
{ make: 'Alfa Romeo', model: 'Giulia' }, | ||
{ make: 'Alfa Romeo', model: 'Stelvio' }, | ||
{ make: 'Ford', model: 'Mustang '}, | ||
{ make: 'Ford', model: 'Focus '}, | ||
{ make: 'Toyota', model: 'Mirai' }, | ||
{ make: 'Toyota', model: 'Yaris' }, | ||
{ make: 'Toyota', model: 'Supra' }, | ||
]; | ||
|
||
filter(car => car.make === 'Ford', cars); // => [ { make: "Ford", model: "Mustang " }, { make: "Ford", model: "Focus " } ] | ||
``` | ||
|
||
### head | ||
|
||
```typescript | ||
import head from "denofun/lib/head.ts"; | ||
|
||
const numbers = [1, 2, 3, 4, 5]; | ||
head(numbers); // => 1 | ||
|
||
// === | ||
|
||
head("hello world!"); // => "h" | ||
``` | ||
|
||
### identity | ||
|
||
```typescript | ||
import identity from "denofun/lib/identity.ts"; | ||
|
||
const x = 5; | ||
identity(x); // => 5 | ||
``` | ||
|
||
### map | ||
|
||
```typescript | ||
import map from "denofun/lib/map.ts"; | ||
|
||
const numbers = [1, 2, 3, 4, 5]; | ||
|
||
map(n => n * 2, numbers); // => [2, 4, 6, 8, 10] | ||
``` | ||
|
||
### pipe | ||
|
||
```typescript | ||
import pipe from "denofun/lib/pipe.ts"; | ||
|
||
function greet(name: string) { | ||
return `hello, ${name}!`; | ||
} | ||
|
||
function makeLoud(x) { | ||
return x.toUpperCase(); | ||
} | ||
|
||
const greetLoudly = pipe(greet, makeLoud); | ||
|
||
greetLoudly('world'); // => HELLO, WORLD! | ||
``` | ||
|
||
### reduce | ||
|
||
```typescript | ||
import reduce from "denofun/lib/reduce.ts"; | ||
|
||
const numbers = [1, 2, 3, 4, 5]; | ||
|
||
const add = (a, b) => a + b; | ||
reduce(add, 0, numbers); // => 15 | ||
``` | ||
|
||
### reverse | ||
|
||
```typescript | ||
import reverse from "denofun/lib/reverse.ts"; | ||
|
||
reverse([1, 2, 3, 4, 5]); // => [5, 4, 3, 2, 1] | ||
|
||
// === | ||
|
||
reverse("hello world!"); // => ["!dlrow olleh"] | ||
``` | ||
|
||
### tail | ||
|
||
```typescript | ||
import tail from "denofun/lib/tail.ts"; | ||
|
||
tail([1, 2, 3, 4, 5]); // => [2, 3, 4, 5] | ||
|
||
// === | ||
|
||
tail("hello world!"); // => "ello world!" | ||
``` | ||
|
||
## Goals | ||
- provide a good replacement for libraries like Ramda or Lodash with "native" Deno feel | ||
- provide basic monads (Either, Maybe/Option) | ||
- good, out-of-the-box typings | ||
|
||
## Non-Goals | ||
- get integrated into `deno_std` as `fun` module | ||
- provide more monads (Future, Stream) |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { test } from "https://deno.land/std/testing/mod.ts"; | ||
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
|
||
import compose from './compose.ts'; | ||
|
||
function add5(n) { | ||
return n + 5; | ||
} | ||
|
||
function mul2(n) { | ||
return n * 2; | ||
} | ||
|
||
function sub(a, b) { | ||
return a - b; | ||
} | ||
|
||
const add5mul2 = compose(mul2, add5); | ||
const mul2sub = compose(mul2, sub); | ||
|
||
test({ | ||
name: "compose", | ||
fn(): void { | ||
assertEquals(add5mul2(5), 20); | ||
assertEquals(add5mul2(2), 14); | ||
assertEquals(mul2sub(2, 5), -6); | ||
} | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import curry from "./curry.ts"; | ||
|
||
function compose(...fns) { | ||
return fns.reduceRight((f, g) => (...args) => g(f(...args))); | ||
} | ||
|
||
export default curry(compose); |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { test } from "https://deno.land/std/testing/mod.ts"; | ||
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
|
||
import curry from './curry.ts'; | ||
|
||
function add(a, b) { | ||
return a + b; | ||
} | ||
|
||
const curriedAdd = curry(add); | ||
const add5 = curriedAdd(5); | ||
const add5and10 = curriedAdd(5, 10); | ||
|
||
test({ | ||
name: "curry", | ||
fn(): void { | ||
assertEquals(typeof curry(add), 'function'); | ||
assertEquals(typeof curriedAdd(5), 'function'); | ||
assertEquals(add5(2), 7); | ||
assertEquals(add5and10, 15); | ||
} | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default function curry(fn) { | ||
return function curried(...args) { | ||
if (args.length >= fn.length) { | ||
return fn(...args); | ||
} | ||
|
||
return function(a) { | ||
return curried(...[...args, a]); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { test } from "https://deno.land/std/testing/mod.ts"; | ||
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; | ||
|
||
import filter from './filter.ts'; | ||
|
||
function isLessThan5(n) { | ||
return n < 5; | ||
} | ||
|
||
test({ | ||
name: "filter", | ||
fn(): void { | ||
assertEquals(filter(isLessThan5, [1, 2, 6, 8]), [1, 2]); | ||
assertEquals(filter(isLessThan5)([1, 2, 6, 8]), [1, 2]); | ||
} | ||
}) |
Oops, something went wrong.