-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New: swap #42
New: swap #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expectType } from 'tsd'; | ||
import { __, pipe, compose, swap } from '../es'; | ||
|
||
const indexA = 0; | ||
const indexB = 1; | ||
const list: number[] = []; | ||
|
||
expectType<number[]>(swap(indexA, indexB, list)); | ||
|
||
expectType<number[]>(swap(__, indexB, list)(indexA)); | ||
|
||
expectType<number[]>(swap(indexA, __, list)(indexB)); | ||
|
||
expectType<number[]>(swap(__, __, list)(indexA, indexB)); | ||
expectType<number[]>(swap(__, __, list)(__, indexB)(indexA)); | ||
expectType<number[]>(swap(__, __, list)(indexA)(indexB)); | ||
|
||
expectType<number[]>(swap(indexA, indexB)(list)); | ||
|
||
expectType<number[]>(swap(__, indexB)(indexA, list)); | ||
expectType<number[]>(swap(__, indexB)(__, list)(indexA)); | ||
expectType<number[]>(swap(__, indexB)(indexA)(list)); | ||
|
||
expectType<number[]>(swap(indexA)(indexB, list)); | ||
expectType<number[]>(swap(indexA)(__, list)(indexB)); | ||
expectType<number[]>(swap(indexA)(indexB)(list)); | ||
|
||
// sanity checks for compose and pipe | ||
expectType<(list: readonly number[]) => number[]>(pipe(swap(indexA, indexB))); | ||
expectType<(list: readonly number[]) => number[]>(compose(swap(indexA, indexB))); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Placeholder } from './util/tools'; | ||
|
||
// swap(indexA) | ||
export function swap(indexA: number): { | ||
// swap(indexA)(indexB)(list) | ||
(indexB: number): <T>(list: readonly T[]) => T[]; | ||
// swap(indexA)(__, list)(indexB) | ||
<T>(__: Placeholder, list: readonly T[]): (indexB: number) => T[]; | ||
// swap(indexA)(indexB, list) | ||
<T>(indexB: number, list: readonly T[]): T[]; | ||
}; | ||
|
||
// swap(__, indexB) | ||
export function swap( | ||
__: Placeholder, | ||
indexB: number | ||
): { | ||
// swap(__, indexB)(indexA)(list) | ||
(indexA: number): <T>(list: readonly T[]) => T[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious about the Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're spot-on, but I wouldn't describe it as "only" doing what it does because I think it's a pretty powerful TS feature. If you have a Every function in Ramda is a pure function so there should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahh, that makes sense. It does help the consumer in that this function now accepts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// swap(__, indexB)(__, list)(indexA) | ||
<T>(__2: Placeholder, list: readonly T[]): (indexA: number) => T[]; | ||
// swap(__, indexB)(indexA, list) | ||
<T>(indexA: number, list: readonly T[]): T[]; | ||
}; | ||
|
||
// swap(indexA, indexB)(list) | ||
export function swap(indexA: number, indexB: number): <T>(list: readonly T[]) => T[]; | ||
|
||
// swap(__, __, list) | ||
export function swap<T>( | ||
__: Placeholder, | ||
__2: Placeholder, | ||
list: readonly T[] | ||
): { | ||
// swap(__, __, list)(indexA)(indexB) | ||
(indexA: number): (indexB: number) => T[]; | ||
// swap(__, __, list)(__, indexB)(indexA) | ||
(__3: Placeholder, indexB: number): (indexA: number) => T[]; | ||
// swap(__, __, list)(indexA, indexB) | ||
(indexA: number, indexB: number): T[]; | ||
}; | ||
|
||
// swap(indexA, __, list)(indexB) | ||
export function swap<T>( | ||
indexA: number, | ||
__: Placeholder, | ||
list: readonly T[] | ||
): (indexB: number) => T[]; | ||
|
||
// swap(__, indexB, list)(indexA) | ||
export function swap<T>( | ||
__: Placeholder, | ||
indexB: number, | ||
list: readonly T[] | ||
): (indexA: number) => T[]; | ||
|
||
// swap(indexA, indexB, list) | ||
export function swap<T>(indexA: number, indexB: number, list: readonly T[]): T[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the comments! Makes all these overloads much easier to follow 👍🏻