Skip to content

Commit

Permalink
Add docs for combinations() function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Jan 30, 2025
1 parent 4eb6660 commit 1c18954
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ Quick Reference
| [`union`](#union) | Union of iterables | `set.union(...iterables)` | `set.unionAsync(...iterables)` |

#### Combinatorics
| Iterator | Description | Sync Code Snippet | Async Code Snippet |
|------------------------------------------------|----------------------------------------|-----------------------------------------------|----------------------------------------------------|
| [`cartesianProduct`](#cartesian-product) | Iterate cartesian product of iterables | `combinations.cartesianProduct(...iterables)` | `combinations.cartesianProductAsync(...iterables)` |
| [`permutations`](#permutations) | Permutations of iterables | `combinations.permutations(data, length)` | `combinations.permutationsAsync(data, length)` |
| Iterator | Description | Sync Code Snippet | Async Code Snippet |
|------------------------------------------|----------------------------------------|-----------------------------------------------|----------------------------------------------------|
| [`cartesianProduct`](#cartesian-product) | Iterate cartesian product of iterables | `combinations.cartesianProduct(...iterables)` | `combinations.cartesianProductAsync(...iterables)` |
| [`combinations`](#combinations) | Combinations of iterables | `combinations.combinations(data, length)` | `combinations.combinationsAsync(data, length)` |
| [`permutations`](#permutations) | Permutations of iterables | `combinations.permutations(data, length)` | `combinations.permutationsAsync(data, length)` |

#### Summary
| Summary | Description | Sync Code Snippet | Async Code Snippet |
Expand Down Expand Up @@ -1646,6 +1647,29 @@ for (const tuple of combinatorics.cartesianProduct(numbers, letters, chars)) {
*/
```

### Combinations
Iterates all combinations of given iterable.

```
function* combinations<T>(
data: Iterable<T> | Iterator<T>,
length: number
): Iterable<Array<T>>
```

```typescript
import { combinatorics } from 'itertools-ts';

const fruits = ['apple', 'banana', 'cherry'];

for (const combination of combinatorics.combinations(fruits, 2)) {
console.log(combination);
}
// ['apple', 'banana']
// ['apple', 'cherry']
// ['banana', 'cherry']
```

### Permutations
Iterates all permutations of given iterable.

Expand Down

0 comments on commit 1c18954

Please sign in to comment.