Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Expose Iterable publicly #502

Open
nandin-borjigin opened this issue Sep 25, 2023 · 0 comments
Open

Expose Iterable publicly #502

nandin-borjigin opened this issue Sep 25, 2023 · 0 comments

Comments

@nandin-borjigin
Copy link

nandin-borjigin commented Sep 25, 2023

Some of the existing operators return Iterable and some others also expect Iterable.
However, due to lack of public operators (like map) on Iterable, we now have to leverage ReadonlyArray in the middle, which can be omitted if internal/Iterable is made public.

declare const set1: HashSet<string>;
declare const set2: HashSet<string>;

const tagged: HashMap<"tag1" | "tag2", string> = pipe(
  HS.values(set1),
  RA.fromIterable,
  RA.map(v => ["tag1", v]),
  RA.appendAll(pipe(
      HS.values(set2),
      RA.fromIterable,
      RA.map(v => ["tag2", v])
  )),
  HM.fromIterable
);

// becomes
const tagged: HashMap<"tag1" | "tag2", string> = pipe(
  HS.values(set1),
  Iterable.map(v => ["tag1", v]),
  Iterable.concat(pipe(
    HS.values(set2),
    Iterable.map(v => ["tag2", v])
  )),
  HM.fromIterable
)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant