Skip to content

Commit

Permalink
feat: add slice and at (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerAberbach authored Oct 20, 2024
1 parent fd6e1ff commit acf2130
Show file tree
Hide file tree
Showing 233 changed files with 6,907 additions and 1,945 deletions.
4 changes: 2 additions & 2 deletions docs/functions/all.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ console.log(

### Defined in

[predicate.d.ts:49](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L49)
[predicate.d.ts:49](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L49)

## all(fn, iterable)

Expand Down Expand Up @@ -105,4 +105,4 @@ console.log(

### Defined in

[predicate.d.ts:49](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L49)
[predicate.d.ts:49](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L49)
4 changes: 2 additions & 2 deletions docs/functions/allAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ console.log(

### Defined in

[predicate.d.ts:69](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L69)
[predicate.d.ts:69](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L69)

## allAsync(fn, asyncIterable)

Expand Down Expand Up @@ -108,4 +108,4 @@ console.log(

### Defined in

[predicate.d.ts:69](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L69)
[predicate.d.ts:69](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L69)
4 changes: 2 additions & 2 deletions docs/functions/allConcur.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ console.log(

### Defined in

[predicate.d.ts:89](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L89)
[predicate.d.ts:89](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L89)

## allConcur(fn, concurIterable)

Expand Down Expand Up @@ -108,4 +108,4 @@ console.log(

### Defined in

[predicate.d.ts:89](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L89)
[predicate.d.ts:89](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L89)
4 changes: 2 additions & 2 deletions docs/functions/any.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ console.log(

### Defined in

[predicate.d.ts:108](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L108)
[predicate.d.ts:108](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L108)

## any(fn, iterable)

Expand Down Expand Up @@ -105,4 +105,4 @@ console.log(

### Defined in

[predicate.d.ts:108](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L108)
[predicate.d.ts:108](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L108)
4 changes: 2 additions & 2 deletions docs/functions/anyAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ console.log(

### Defined in

[predicate.d.ts:128](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L128)
[predicate.d.ts:128](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L128)

## anyAsync(fn, asyncIterable)

Expand Down Expand Up @@ -108,4 +108,4 @@ console.log(

### Defined in

[predicate.d.ts:128](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L128)
[predicate.d.ts:128](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L128)
4 changes: 2 additions & 2 deletions docs/functions/anyConcur.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ console.log(

### Defined in

[predicate.d.ts:148](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L148)
[predicate.d.ts:148](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L148)

## anyConcur(fn, concurIterable)

Expand Down Expand Up @@ -108,4 +108,4 @@ console.log(

### Defined in

[predicate.d.ts:148](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/predicate.d.ts#L148)
[predicate.d.ts:148](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/predicate.d.ts#L148)
2 changes: 1 addition & 1 deletion docs/functions/asAsync.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ for await (const value of asyncIterable) {

## Defined in

[as.d.ts:27](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/as.d.ts#L27)
[as.d.ts:27](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/as.d.ts#L27)
2 changes: 1 addition & 1 deletion docs/functions/asConcur.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ await forEachConcur(console.log, concurIterable)

## Defined in

[as.d.ts:77](https://github.com/TomerAberbach/lfi/blob/e98b31ea37c84de0758cf58c8fcf28193f36b533/src/operations/as.d.ts#L77)
[as.d.ts:77](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/as.d.ts#L77)
138 changes: 138 additions & 0 deletions docs/functions/at.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
[**lfi**](../readme.md)**Docs**

***

[lfi](../globals.md) / at

# Function: at()

Returns an iterable containing the value at the given `index` of `iterable`
or an empty iterable if `index` is out of bounds.

WARNING: This function linearly iterates up to `index` because iterables do
not support random access.

## Throws

if `index` is not a non-negative integer.

## Example

```js
const iterable = [`sloth`, `more sloth`, `even more sloth`]

console.log(
pipe(
iterable,
at(1),
get,
),
)
//=> 'more sloth'
```

## at(index)

> **at**\<`Index`\>(`index`): \<`Value`\>(`iterable`) => [`Optional`](../type-aliases/Optional.md)\<`Value`\>
Returns an iterable containing the value at the given `index` of `iterable`
or an empty iterable if `index` is out of bounds.

WARNING: This function linearly iterates up to `index` because iterables do
not support random access.

### Type Parameters

**Index** *extends* `number`

### Parameters

**index**: `NonNegativeInteger`\<`Index`\>

### Returns

`Function`

#### Type Parameters

**Value**

#### Parameters

**iterable**: `Iterable`\<`Value`, `any`, `any`\>

#### Returns

[`Optional`](../type-aliases/Optional.md)\<`Value`\>

### Throws

if `index` is not a non-negative integer.

### Example

```js
const iterable = [`sloth`, `more sloth`, `even more sloth`]

console.log(
pipe(
iterable,
at(1),
get,
),
)
//=> 'more sloth'
```

### Defined in

[slice.d.ts:706](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/slice.d.ts#L706)

## at(index, iterable)

> **at**\<`Index`, `Value`\>(`index`, `iterable`): [`Optional`](../type-aliases/Optional.md)\<`Value`\>
Returns an iterable containing the value at the given `index` of `iterable`
or an empty iterable if `index` is out of bounds.

WARNING: This function linearly iterates up to `index` because iterables do
not support random access.

### Type Parameters

**Index** *extends* `number`

**Value**

### Parameters

**index**: `NonNegativeInteger`\<`Index`\>

**iterable**: `Iterable`\<`Value`, `any`, `any`\>

### Returns

[`Optional`](../type-aliases/Optional.md)\<`Value`\>

### Throws

if `index` is not a non-negative integer.

### Example

```js
const iterable = [`sloth`, `more sloth`, `even more sloth`]

console.log(
pipe(
iterable,
at(1),
get,
),
)
//=> 'more sloth'
```

### Defined in

[slice.d.ts:709](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/slice.d.ts#L709)
138 changes: 138 additions & 0 deletions docs/functions/atAsync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
[**lfi**](../readme.md)**Docs**

***

[lfi](../globals.md) / atAsync

# Function: atAsync()

Returns an async iterable containing the value at the given `index` of
`asyncIterable` or an empty async iterable if `index` is out of bounds.

WARNING: This function linearly iterates up to `index` because async
iterables do not support random access.

## Throws

if `index` is not a non-negative integer.

## Example

```js
const asyncIterable = asAsync([`sloth`, `more sloth`, `even more sloth`])

console.log(
await pipe(
asyncIterable,
atAsync(1),
getAsync,
),
)
//=> 'more sloth'
```

## atAsync(index)

> **atAsync**\<`Index`\>(`index`): \<`Value`\>(`asyncIterable`) => [`AsyncOptional`](../type-aliases/AsyncOptional.md)\<`Value`\>
Returns an async iterable containing the value at the given `index` of
`asyncIterable` or an empty async iterable if `index` is out of bounds.

WARNING: This function linearly iterates up to `index` because async
iterables do not support random access.

### Type Parameters

**Index** *extends* `number`

### Parameters

**index**: `NonNegativeInteger`\<`Index`\>

### Returns

`Function`

#### Type Parameters

**Value**

#### Parameters

**asyncIterable**: `AsyncIterable`\<`Value`, `any`, `any`\>

#### Returns

[`AsyncOptional`](../type-aliases/AsyncOptional.md)\<`Value`\>

### Throws

if `index` is not a non-negative integer.

### Example

```js
const asyncIterable = asAsync([`sloth`, `more sloth`, `even more sloth`])

console.log(
await pipe(
asyncIterable,
atAsync(1),
getAsync,
),
)
//=> 'more sloth'
```

### Defined in

[slice.d.ts:739](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/slice.d.ts#L739)

## atAsync(index, asyncIterable)

> **atAsync**\<`Index`, `Value`\>(`index`, `asyncIterable`): [`AsyncOptional`](../type-aliases/AsyncOptional.md)\<`Value`\>
Returns an async iterable containing the value at the given `index` of
`asyncIterable` or an empty async iterable if `index` is out of bounds.

WARNING: This function linearly iterates up to `index` because async
iterables do not support random access.

### Type Parameters

**Index** *extends* `number`

**Value**

### Parameters

**index**: `NonNegativeInteger`\<`Index`\>

**asyncIterable**: `AsyncIterable`\<`Value`, `any`, `any`\>

### Returns

[`AsyncOptional`](../type-aliases/AsyncOptional.md)\<`Value`\>

### Throws

if `index` is not a non-negative integer.

### Example

```js
const asyncIterable = asAsync([`sloth`, `more sloth`, `even more sloth`])

console.log(
await pipe(
asyncIterable,
atAsync(1),
getAsync,
),
)
//=> 'more sloth'
```

### Defined in

[slice.d.ts:742](https://github.com/TomerAberbach/lfi/blob/fd6e1ff9d7b7d249090f89ead6d0a30e26aba2e4/src/operations/slice.d.ts#L742)
Loading

0 comments on commit acf2130

Please sign in to comment.