Skip to content

Commit

Permalink
refactor: get -> at
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerAberbach committed Apr 13, 2024
1 parent 0c3adce commit 1fc0831
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ queue.push(3)
console.log(queue.size)
//=> 3

console.log(queue.get(0))
console.log(queue.get(1))
console.log(queue.get(2))
console.log(queue.get(3))
console.log(queue.get(-1))
console.log(queue.at(0))
console.log(queue.at(1))
console.log(queue.at(2))
console.log(queue.at(3))
console.log(queue.at(-1))
//=> 1
//=> 2
//=> 3
Expand Down Expand Up @@ -82,11 +82,11 @@ deque.unshift(0)
console.log(deque.size)
//=> 4

console.log(deque.get(0))
console.log(deque.get(1))
console.log(deque.get(2))
console.log(deque.get(3))
console.log(deque.get(-1))
console.log(deque.at(0))
console.log(deque.at(1))
console.log(deque.at(2))
console.log(deque.at(3))
console.log(deque.at(-1))
//=> 0
//=> 1
//=> 2
Expand Down
4 changes: 2 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ declare class Queue<Value> {
* Returns the value at the given `index` with wrap around, or `undefined` if
* the queue is empty.
*/
public get(index: number): Value | undefined
public at(index: number): Value | undefined

/** Adds `value` to the end of the queue. */
public push(value: Value): void
Expand Down Expand Up @@ -63,7 +63,7 @@ declare class Deque<Value> {
* Returns the value at the given `index` with wrap around, or `undefined` if
* the deque is empty.
*/
public get(index: number): Value | undefined
public at(index: number): Value | undefined

/** Adds `value` to the end of the deque. */
public push(value: Value): void
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Queue {
return (this._startIndex + index) & (this._data.length - 1)
}

get(index) {
at(index) {
return this._data[
this._mask(((index % this._size) + this._size) % this._size)
]
Expand Down Expand Up @@ -65,7 +65,7 @@ export class Queue {

*[Symbol.iterator]() {
for (let i = 0; i < this._size; i++) {
yield this.get(i)
yield this.at(i)
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const {
spreadCommand,
} = toCommands<unknown[], Deque<unknown>>({
get: (model, real, index: number) => {
expect(real.get(index)).toBe(
expect(real.at(index)).toBe(
model[((index % model.length) + model.length) % model.length],
)
},
Expand Down Expand Up @@ -123,7 +123,7 @@ test.prop(
test.skip(`types`, () => {
const queue = new Queue<number>()

expectTypeOf<number | undefined>(queue.get(0))
expectTypeOf<number | undefined>(queue.at(0))
expectTypeOf<void>(queue.push(1))
expectTypeOf<number | undefined>(queue.shift())
expectTypeOf<number[]>([...queue])
Expand All @@ -132,7 +132,7 @@ test.skip(`types`, () => {

const deque = new Deque<string>()

expectTypeOf<string | undefined>(deque.get(0))
expectTypeOf<string | undefined>(deque.at(0))
expectTypeOf<void>(deque.push(`wow`))
expectTypeOf<string | undefined>(deque.pop())
expectTypeOf<void>(deque.unshift(`wow`))
Expand Down

0 comments on commit 1fc0831

Please sign in to comment.