NonEmptyList2
/// a data type which represents a non empty list of A.
/// single element (head) and optional structure (tail).
struct NonEmptyArray {
let head(T)
let tail: [T]
}
2 Swiftඪ४ܕͰList͕ଘࡏ͠ͳ͍ͷͰɺArrayΛࣄྫʹͯ͠ѻ͏
13
Validation(Nel)
• Monad
• Applicative Functor
• https://typelevel.org/cats/datatypes/validated.html
/// `Result` with success-value, `nel` as the failure type.
enum Validated {
case valid(Value)
case invalid(NonEmptyArray)
}
26
Slide 27
Slide 27 text
Kotlin: arrow.Validated
• https://arrow-kt.io/docs/datatypes/validated/
@higherkind sealed class Validated : ValidatedOf {
data class Valid(val a: A) : Validated()
data class Invalid(val e: E) : Validated()
}
27
Slide 28
Slide 28 text
e.g
let validatedPassword: Validated ...
switch validatedPassword {
case .valid(let value):
print(value)
case .invalid(let errors):
// e.g. preset `errors.first` messages
}
28