Skip to content

Commit

Permalink
rename to tupled
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Dec 24, 2019
1 parent fbd0b29 commit 9f36f9c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ high state of flux, you're at risk of it changing without notice.
- `StateReaderTaskEither`
- add `chainEither`, `chainIOEither`, `chainTaskEither`, `chainReaderTaskEither` (@gcanti)
- `function`
- add `unary` function, closes #1062 (@gcanti)
- add `tupled` function, closes #1062 (@gcanti)
- **Deprecation**
- `Ord`
- deprecate `getSemigroup` in favor of `getMonoid` (@gcanti)
Expand Down
12 changes: 6 additions & 6 deletions docs/modules/function.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Added in v2.0.0
- [increment (function)](#increment-function)
- [not (function)](#not-function)
- [tuple (function)](#tuple-function)
- [unary (function)](#unary-function)
- [tupled (function)](#tupled-function)

---

Expand Down Expand Up @@ -340,22 +340,22 @@ export function tuple<T extends Array<any>>(...t: T): T { ... }

Added in v2.0.0

# unary (function)
# tupled (function)

Returns a unary function from a `n`-ary function
Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument.

**Signature**

```ts
export function unary<A extends Array<unknown>, B>(f: (...a: A) => B): (a: A) => B { ... }
export function tupled<A extends Array<unknown>, B>(f: (...a: A) => B): (a: A) => B { ... }
```

**Example**

```ts
import { unary } from 'fp-ts/lib/function'
import { tupled } from 'fp-ts/lib/function'

const add = unary((x: number, y: number): number => x + y)
const add = tupled((x: number, y: number): number => x + y)

assert.strictEqual(add([1, 2]), 3)
```
Expand Down
4 changes: 2 additions & 2 deletions dtslint/ts3.5/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ Fu.tuple(1, 'a', true) // $ExpectType [number, string, boolean]
// $ExpectType <A>(head: A, tail: A[]) => Option<A>
Fu.flow(A.cons, A.head)

// unary
Fu.unary(A.insertAt) // $ExpectType <A>(a: [number, A]) => (as: A[]) => Option<A[]>
// tupled
Fu.tupled(A.insertAt) // $ExpectType <A>(a: [number, A]) => (as: A[]) => Option<A[]>

//
// Filterable overloads
Expand Down
8 changes: 4 additions & 4 deletions src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,17 @@ export function absurd<A>(_: never): A {
}

/**
* Returns a unary function from a `n`-ary function
* Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument.
*
* @example
* import { unary } from 'fp-ts/lib/function'
* import { tupled } from 'fp-ts/lib/function'
*
* const add = unary((x: number, y: number): number => x + y)
* const add = tupled((x: number, y: number): number => x + y)
*
* assert.strictEqual(add([1, 2]), 3)
*
* @since 2.4.0
*/
export function unary<A extends Array<unknown>, B>(f: (...a: A) => B): (a: A) => B {
export function tupled<A extends Array<unknown>, B>(f: (...a: A) => B): (a: A) => B {
return a => f(...a)
}
8 changes: 4 additions & 4 deletions test/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
unsafeCoerce,
absurd,
flow,
unary
tupled
} from '../src/function'

const f = (n: number) => n + 1
Expand Down Expand Up @@ -80,11 +80,11 @@ describe('function', () => {
assert.deepStrictEqual(flow(f, g, f, g, f, g, f, g, f)(2), 63)
})

it('unary', () => {
it('tupled', () => {
const f1 = (a: number): number => a * 2
const f2 = (a: number, b: number): number => a + b
const u1 = unary(f1)
const u2 = unary(f2)
const u1 = tupled(f1)
const u2 = tupled(f2)
assert.deepStrictEqual(u1.length, 1)
assert.deepStrictEqual(u1([1]), 2)
assert.deepStrictEqual(u2.length, 1)
Expand Down

0 comments on commit 9f36f9c

Please sign in to comment.