-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUser.kt
36 lines (32 loc) · 1.03 KB
/
User.kt
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
// Copyright © FunctionalKotlin.com 2017. All rights reserved.
import Validators.Adult
import Validators.Email
import Validators.Name
import Validators.Newsletter
import Validators.Password
import Validators.Premium
import java.time.LocalDate
data class User(
val name: String, val password: String,
val premium: Boolean, val newsletter: Boolean,
val birthDate: LocalDate, val email: String)
enum class UserError {
USERNAME_OUT_OF_BOUNDS,
PASSWORD_TOO_SHORT,
MUST_BE_PREMIUM,
MUST_ACCEPT_NEWSLETTER,
MUST_BE_ADULT,
WRONG_EMAIL
}
fun createUser(
name: String, password: String, premium: Boolean,
newsletter: Boolean, birthDate: LocalDate,
email: String): AsyncResult<User, UserError> =
Future.pure(Result.pure(::User.curried())) ap
Name(name) ap
Password(password) ap
Future.pure(Result.pure(premium)) ap
Future.pure(Result.pure(newsletter)) ap
Adult(birthDate) ap
Email(email) bind
(Premium or Newsletter)