-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Tim <hello@timsmart.co>
- Loading branch information
Showing
5 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
"effect": minor | ||
--- | ||
|
||
Add `Random.choice`. | ||
|
||
```ts | ||
import { Random } from "effect" | ||
|
||
Effect.gen(function* () { | ||
const randomItem = yield* Random.choice([1, 2, 3]) | ||
console.log(randomItem) | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type * as Array from "../src/Array.js" | ||
import type { Chunk } from "../src/index.js" | ||
import * as Random from "../src/Random.js" | ||
|
||
declare const array: Array<number> | ||
declare const nonEmptyArray: Array.NonEmptyArray<number> | ||
|
||
// $ExpectType Effect<number, NoSuchElementException, never> | ||
Random.choice(array) | ||
|
||
// $ExpectType Effect<number, never, never> | ||
Random.choice(nonEmptyArray) | ||
|
||
declare const readonlyArray: Array<number> | ||
declare const nonEmptyReadonlyArray: Array.NonEmptyArray<number> | ||
|
||
// $ExpectType Effect<number, NoSuchElementException, never> | ||
Random.choice(readonlyArray) | ||
|
||
// $ExpectType Effect<number, never, never> | ||
Random.choice(nonEmptyReadonlyArray) | ||
|
||
declare const chunk: Chunk.Chunk<number> | ||
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number> | ||
|
||
// $ExpectType Effect<number, NoSuchElementException, never> | ||
Random.choice(chunk) | ||
|
||
// $ExpectType Effect<number, never, never> | ||
Random.choice(nonEmptyChunk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters