Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utilities for tuple comparisons #602

Open
ggreif opened this issue Dec 3, 2023 · 0 comments
Open

utilities for tuple comparisons #602

ggreif opened this issue Dec 3, 2023 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ggreif
Copy link
Contributor

ggreif commented Dec 3, 2023

I came up with these:

    type Comp = { #less; #equal; #greater };
    // Comparison combinators
    public func compare2<A, B>(ca : (A, A) -> Comp, cb : (B, B) -> Comp)
      : ((A, B), (A, B)) -> Comp =
      func((a1 : A, b1 : B), (a2 : A, b2 : B)) : Comp =
        switch (ca(a1, a2)) {
          case (#equal) cb(b1, b2);
          case other other
        };

    public func compare3<A, B, C>(ca : (A, A) -> Comp,
                                  cbc : ((B, B) -> Comp, (C, C) -> Comp))
      : ((A, (B, C)), (A, (B, C))) -> Comp
      = compare2(ca, compare2 cbc);

We could have a helper module giving these a home?

Tracked here too: https://dfinity.atlassian.net/browse/LANG-331

@ggreif ggreif added enhancement New feature or request good first issue Good for newcomers labels Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant