Skip to content

Commit

Permalink
docs: fix Result usage (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet committed Aug 5, 2022
1 parent 1e11f53 commit fb07af0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/lib/parsers/Args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,14 @@ export class Args {
* const resolver = Args.make((arg) => ok(arg.split('').reverse().join('')));
*
* const result = await args.peekResult(() => args.repeatResult(resolver));
* if (isOk(result)) await message.channel.send(
* `Reversed ${result.value.length} word(s): ${result.value.join(' ')}`
* await result.inspectAsync((value) =>
* message.channel.send(`Reversed ${value.length} word(s): ${value.join(' ')}`)
* ); // Reversed 2 word(s): olleh dlrow
*
* const firstWord = await args.pickResult('string');
* if (isOk(firstWord)) await message.channel.send(firstWord.value.toUpperCase()); // HELLO
* await firstWord.inspectAsync((value) =>
* message.channel.send(firstWord.value.toUpperCase())
* ); // HELLO
* ```
*/
public async peekResult<T>(type: () => Argument.Result<T>): Promise<ResultType<T>>;
Expand All @@ -374,10 +376,10 @@ export class Args {
* const resolver = Args.make((arg) => ok(arg.split('').reverse().join('')));
*
* const peekedWord = await args.peekResult(resolver);
* if (isOk(peekedWord)) await message.channel.send(peekedWord.value); // erihppas
* await peekedWord.inspectAsync((value) => message.channel.send(peekedWord.value)); // erihppas
*
* const firstWord = await args.pickResult('string');
* if (isOk(firstWord)) await message.channel.send(firstWord.value.toUpperCase()); // SAPPHIRE
* await firstWord.inspectAsync((value) => message.channel.send(value.toUpperCase())); // SAPPHIRE
* ```
*/
public async peekResult<T>(type: IArgument<T>, options?: ArgOptions): Promise<ResultType<T>>;
Expand All @@ -391,12 +393,14 @@ export class Args {
* ```typescript
* // !datethenaddtwo 1608867472611
* const date = await args.peekResult('date');
* if (isOk(date)) await message.channel.send(
* `Your date (in UTC): ${date.value.toUTCString()}`
* await date.inspectAsync((value) =>
* message.channel.send(`Your date (in UTC): ${date.value.toUTCString()}`)
* ); // Your date (in UTC): Fri, 25 Dec 2020 03:37:52 GMT
*
* const result = await args.pickResult('number', { maximum: Number.MAX_SAFE_INTEGER - 2 });
* if (isOk(result)) await message.channel.send(`Your number plus two: ${result.value + 2}`); // Your number plus two: 1608867472613
* await result.inspectAsync((value) =>
* message.channel.send(`Your number plus two: ${result.value + 2}`)
* ); // Your number plus two: 1608867472613
* ```
*/
public async peekResult<K extends keyof ArgType>(
Expand Down

0 comments on commit fb07af0

Please sign in to comment.