Skip to content

Commit

Permalink
Guarantee that map executes in order in JS (#1002)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfellis authored Dec 10, 2024
1 parent 810c3bb commit e3d6d16
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions alan/src/std/root.ln
Original file line number Diff line number Diff line change
Expand Up @@ -1217,9 +1217,9 @@ fn push{T} (a: Mut{T[]}, v: T) = {Method{"push"} :: (Mut{T[]}, Own{T})}(a, v);
fn{Rs} pop{T} (a: Mut{T[]}) -> T? = {Method{"pop"} :: Mut{T[]} -> T?}(a);
fn{Js} pop{T} (a: Mut{T[]}) -> T? = {"((a) => a || null)" :: T? -> T?}({Method{"pop"} :: Mut{T[]} -> T?}(a));
fn{Rs} map{T, U} "alan_std::map_onearg" <- RootBacking :: (T[], T -> U) -> U[];
fn{Js} map{T, U} (a: T[], f: T -> U) = {"Promise.all" :: U[] -> U[]}({Method{"map"} :: (T[], T -> U) -> U[]}(a, f));
fn{Js} map{T, U} "(async (a, f) => { let out = []; for (let v of a) { out.push(await f(v)); } return out; })" :: (T[], f: T -> U) -> U[];
fn{Rs} map{T, U} "alan_std::map_twoarg" <- RootBacking :: (T[], (T, i64) -> U) -> U[];
fn{Js} map{T, U} (a: T[], f: (T, i64) -> U) = {"Promise.all" :: U[] -> U[]}({Method{"map"} :: (T[], (T, i32) -> U) -> U[]}(a, fn (v: T, i: i32) = f(v, i.i64)));
fn{Js} map{T, U} "(async (a, f) => { let out = []; for (let i = 0; i < a.length; i++) { out.push(await f(a[i], new alan_std.I64(i))); } return out; })" <- RootBacking :: (T[], f: (T, i64) -> U) -> U[];
fn{Rs} parmap{T, U} "alan_std::parmap_onearg" <- RootBacking :: (T[], T -> U) -> U[];
fn{Rs} filter{T} "alan_std::filter_onearg" <- RootBacking :: (T[], T -> bool) -> T[];
fn{Js} filter{T} (a: T[], f: T -> bool) = {"(async (a, f) => { let out = []; for (let v of a) { if ((await f(v)).val) { out.push(v); } } return out; })" :: (T[], T -> bool) -> T[]}(a, f);
Expand Down

0 comments on commit e3d6d16

Please sign in to comment.