Skip to content

Commit

Permalink
refactor(transducers): remove obsolete randomID() & weightedRandom()
Browse files Browse the repository at this point in the history
BREAKING CHANGE: migrate randomID() & weightedRandom() to @thi.ng/random

- update choices() iterator
  • Loading branch information
postspectacular committed Feb 12, 2019
1 parent f719724 commit 4b0eec6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 65 deletions.
25 changes: 0 additions & 25 deletions packages/transducers/src/func/random-id.ts

This file was deleted.

36 changes: 0 additions & 36 deletions packages/transducers/src/func/weighted-random.ts

This file was deleted.

8 changes: 4 additions & 4 deletions packages/transducers/src/iter/choices.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { weightedRandom } from "../func/weighted-random";
import { ensureArray } from "@thi.ng/arrays";
import { IRandom, SYSTEM, weightedRandom } from "@thi.ng/random";
import { repeatedly } from "./repeatedly";
import { IRandom, SYSTEM } from "@thi.ng/random";

/**
* Returns an infinite iterator of random choices and their (optional)
Expand All @@ -19,11 +19,11 @@ import { IRandom, SYSTEM } from "@thi.ng/random";
*/
export const choices = <T>(
choices: ArrayLike<T> & Iterable<T>,
weights?: ArrayLike<number> & Iterable<number>,
weights?: ArrayLike<number>,
rnd: IRandom = SYSTEM
) =>
repeatedly(
weights ?
weightedRandom(choices, weights, rnd) :
weightedRandom(ensureArray(choices), weights, rnd) :
() => choices[(rnd.float(choices.length) | 0)]
);

0 comments on commit 4b0eec6

Please sign in to comment.