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

Improve Regex equality #839

Closed
pauldijou opened this Issue Feb 12, 2017 · 5 comments

Comments

Projects
None yet
5 participants
@pauldijou

pauldijou commented Feb 12, 2017

Right now, any Elm regex is considered equal to any other regex even if their definitions are totally different. Check demo.

Maybe improve Native.Utils.eq to perform a special check when testing regexps. Found this code browsing SO:

function regexSame(r1, r2) {
    if (r1 instanceof RegExp && r2 instanceof RegExp) {
        var props = ["global", "multiline", "ignoreCase", "source"];
        for (var i = 0; i < props.length; i++) {
            var prop = props[i];
            if (r1[prop] !== r2[prop]) {
                return false;
            }
        }
        return true;
    }
    return false;
}
@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Feb 12, 2017

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Feb 12, 2017

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@lukewestby

This comment has been minimized.

Show comment
Hide comment
@lukewestby

lukewestby Mar 3, 2017

Member

@pauldijou can you share some reasons why you would want to check the equality of two regex values?

Member

lukewestby commented Mar 3, 2017

@pauldijou can you share some reasons why you would want to check the equality of two regex values?

@pauldijou

This comment has been minimized.

Show comment
Hide comment
@pauldijou

pauldijou Mar 3, 2017

I was messing around implementing a Map (like a Dict but with any type of key) and using Regex as keys broke it since all regexs were considered equals.

pauldijou commented Mar 3, 2017

I was messing around implementing a Map (like a Dict but with any type of key) and using Regex as keys broke it since all regexs were considered equals.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Mar 26, 2017

Member

Regex is similar to functions when it comes to equality. We will eventually be able to disallow using (==) on them statically, but it's not possible for now. So this will be "improved" by turning it into a compilation error once the compiler work happens.

Member

evancz commented Mar 26, 2017

Regex is similar to functions when it comes to equality. We will eventually be able to disallow using (==) on them statically, but it's not possible for now. So this will be "improved" by turning it into a compilation error once the compiler work happens.

@evancz evancz closed this Mar 26, 2017

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Mar 26, 2017

Contributor

Maybe a note about Regex at http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#== would be in place.

Contributor

jvoigtlaender commented Mar 26, 2017

Maybe a note about Regex at http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#== would be in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment