Skip to content

Commit e02ff42

Browse files
committed
allow single argument
1 parent 226ff59 commit e02ff42

File tree

6 files changed

+9
-19
lines changed

6 files changed

+9
-19
lines changed

.github/CONTRIBUTING.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,4 @@ pnpm add pipe-function
2626
import { pipe } from "pipe-function";
2727
```
2828

29-
Takes between 2 and 20 arguments. `pipe(x, a, b)` is equivalent to `b(a(x))`, in other words, this function pipes a value through a number of functions in the order that they appear. [This article](https://dev.to/ivan7237d/i-ve-used-the-pipe-function-2-560-times-and-i-can-tell-you-it-s-good-4aal) talks about why this function is useful.
30-
31-
When you have a single argument, like `const y = pipe(x)`, `pipe` is redundant, so you will get a type error, but the code will run and return `x`. Despite the type error, the type of `y` will be inferred correctly as type of `x`.
32-
33-
---
34-
35-
[Contributing guidelines](https://github.com/ivan7237d/pipe-function/blob/master/.github/CONTRIBUTING.md)
29+
Takes between 1 and 20 arguments. `pipe(x, a, b)` is equivalent to `b(a(x))`, in other words, this function pipes a value through a number of functions in the order that they appear. [This article](https://dev.to/ivan7237d/i-ve-used-the-pipe-function-2-560-times-and-i-can-tell-you-it-s-good-4aal) talks about why this function is useful.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [1.0.2]
4+
5+
Type signature changed to allow a single argument.
6+
37
## [1.0.1]
48

59
Type signature changed in such a way that when you write `const y = pipe(x)`, you still get a type error, but the type of `y` is inferred as type of `x` instead of `unknown`.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pipe-function",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A function to pipe a value through a number of transforms",
55
"repository": "https://github.com/ivan7237d/pipe-function.git",
66
"license": "MIT",

src/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ const addSuffix =
77

88
test("", () => {
99
// $ExpectType "base"
10-
const result =
11-
// @ts-expect-error
12-
pipe("base" as const);
10+
const result = pipe("base" as const);
1311
expect(result).toMatchInlineSnapshot(`"base"`);
1412

1513
expect(

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
type Pipe = {
2-
<T, A = T>(source: T, a: (value: T) => A): A;
2+
<T>(source: T): T;
3+
<T, A>(source: T, a: (value: T) => A): A;
34
<T, A, B>(source: T, a: (value: T) => A, b: (value: A) => B): B;
45
<T, A, B, C>(
56
source: T,

0 commit comments

Comments
 (0)