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

Suggestion for improvement to email check in Validation case study #224

Open
nathanmbrown opened this issue Dec 8, 2022 · 0 comments
Open

Comments

@nathanmbrown
Copy link

nathanmbrown commented Dec 8, 2022

Instead of creating a Check with specific logic for the splitEmail, why not leverage the existing containsOnce predicate and also the map method that the reader has taken time to implement in this exercise?
Also there is no need to convert to an intermediate Tuple...

val splitEmail: Check[Errors, String, Array[String]] = Check(containsOnce('@')) map (_.split('@'))

val checkLeft: Check[Errors, String, String] =
  Check(longerThan(0))

val checkRight: Check[Errors, String, String] =
  Check(longerThan(3) and contains('.'))

val joinEmail: Check[Errors, Array[String], String] =
  Check { case Array(l, r) => (checkLeft(l), checkRight(r)).mapN(_ + "@" + _) }

val checkEmail: Check[Errors, String, String] =
  splitEmail andThen joinEmail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant