/
char.scala
51 lines (38 loc) · 1.55 KB
/
char.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package eu.timepit.refined
import eu.timepit.refined.api.Validate
import eu.timepit.refined.boolean.Or
/** Module for `Char` related predicates. */
object char {
/** Predicate that checks if a `Char` is a digit. */
final case class Digit()
/** Predicate that checks if a `Char` is a letter. */
final case class Letter()
/** Predicate that checks if a `Char` is a lower case character. */
final case class LowerCase()
/** Predicate that checks if a `Char` is an upper case character. */
final case class UpperCase()
/** Predicate that checks if a `Char` is white space. */
final case class Whitespace()
/** Predicate that checks if a `Char` is a letter or digit. */
type LetterOrDigit = Letter Or Digit
object Digit {
implicit def digitValidate: Validate.Plain[Char, Digit] =
Validate.fromPredicate(_.isDigit, t => s"isDigit('$t')", Digit())
}
object Letter {
implicit def letterValidate: Validate.Plain[Char, Letter] =
Validate.fromPredicate(_.isLetter, t => s"isLetter('$t')", Letter())
}
object LowerCase {
implicit def lowerCaseValidate: Validate.Plain[Char, LowerCase] =
Validate.fromPredicate(_.isLower, t => s"isLower('$t')", LowerCase())
}
object UpperCase {
implicit def upperCaseValidate: Validate.Plain[Char, UpperCase] =
Validate.fromPredicate(_.isUpper, t => s"isUpper('$t')", UpperCase())
}
object Whitespace {
implicit def whitespaceValidate: Validate.Plain[Char, Whitespace] =
Validate.fromPredicate(_.isWhitespace, t => s"isWhitespace('$t')", Whitespace())
}
}