Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed Jul 25, 2024
1 parent b5d57ab commit 2ce19fb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
10 changes: 5 additions & 5 deletions data_structures/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function isFailure(result) {
/**
* Throw an error for unsupported kinds.
* @param {string} kind - The unsupported kind.
* @throws Will throw an error with the unsupported kind message.
* @throws Error - Will throw an error with the unsupported kind message.
*/
export function throwUnsupportedKind(kind) {
throwError(`Unsupported kind: ${kind}`);
Expand All @@ -116,7 +116,7 @@ export function throwUnsupportedKind(kind) {
* @example
* ```js
* const result = mapResult(async (value) => value + "!")(Promise.resolve(succeed("Hello")));
* result.then(console.log); // { value: "Hello!", kind: "success" }
* console.log(await result); // { value: "Hello!", kind: "success" }
* ```
*/
export function mapResult(f) {
Expand Down Expand Up @@ -288,11 +288,11 @@ export async function transformResultToPromise(result) {
* ```
*/
export function tryCatch(f) {
return async (input) => {
return async (input, error) => {
try {
return succeed(await f(input));
} catch (error) {
return fail(error);
} catch (err) {
return fail(typeof error === "undefined" ? err : error);
}
};
}
19 changes: 19 additions & 0 deletions generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,22 @@ export async function transformAsyncIterableToPromise(iterable) {
}
return result;
}

/*
* ```js
* const arrN = [10, 20, Promise.resolve("Value from promise 1")];
* const gen = cyclicIterator(arrN);
* console.log(await gen.next());
* console.log(await gen.next());
* console.log(await gen.next());
* console.log(await gen.next());
* ```
*/
async function* cyclicIterator(iterable) {
let index = 0;
while (true) {
const resolvedValue = await iterable[index];
yield resolvedValue;
index = (index + 1) % iterable.length;
}
}
8 changes: 4 additions & 4 deletions math/set.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isSingle } from "./collections/length.js";
import { is2DArray } from "./type.js";
import { reduce } from "./arrays/aggregation.js";
import { single } from "./collections/single_access.js";
import { isSingle } from "../collections/length.js";
import { is2DArray } from "../type.js";
import { reduce } from "../arrays/aggregation.js";
import { single } from "../collections/single_access.js";

/**
* unique.
Expand Down

0 comments on commit 2ce19fb

Please sign in to comment.