rtfeldman / elm-validate

Convenience functions for validating Elm data.
http://package.elm-lang.org/packages/rtfeldman/elm-validate/latest
BSD 3-Clause "New" or "Revised" License
145 stars 28 forks source link

`ifNotFloat` has different behavior than `ifNotInt` #43

Open jaredramirez opened 4 years ago

jaredramirez commented 4 years ago

The function ifNotFloat will error if the subject is a float, whereas ifNotInt will error if the subject is not an int. I believe the behavior of ifNotInt is correct. In the definition of isNotFloat, ifTrue, should be ifFalse.

The current definition:

ifNotFloat : (subject -> String) -> error -> Validator error subject
ifNotFloat subjectToString error =
    ifTrue (\subject -> isFloat (subjectToString subject)) error

The correct definition:

ifNotFloat : (subject -> String) -> error -> Validator error subject
ifNotFloat subjectToString error =
    ifFalse (\subject -> isFloat (subjectToString subject)) error

Note: The definition of ifNotFloat and ifNotInt also differ in the second argument as well. ifNotInt takes a function with the invalid int, whereas ifNotFloat takes just the error. Any changes to ifNotFloat should probably also reconcile the definitions to be the same.