Skip to content

Commit

Permalink
Merge pull request #955 from thefrontside/v4-constant-docs
Browse files Browse the repository at this point in the history
πŸ“ document the `constant()` function
  • Loading branch information
cowboyd authored Jan 6, 2025
2 parents e32a658 + 035179d commit cdf515c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/constant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import type { Operation } from "./types.ts";

/**
* Create an {@link Operation} that always evaluates to `value`.
*
* @example
*
* ```ts
* let x = yield* constant("hello world");
* x === "hello world" //=> true
* ```
*
* @returns the {@link Operation} that evaluates to `value`;
*/
export function constant<T>(value: T): Operation<T> {
return {
[Symbol.iterator]: () => ({ next: () => ({ done: true, value }) }),
Expand Down

0 comments on commit cdf515c

Please sign in to comment.