This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Create type alias for the function | |
| typealias MessageCreatorFactory = (PhoneNumber, String, String) -> MessageCreator | |
| @Service | |
| class NotificationService( | |
| private val restClient: TwilioRestClient, | |
| private val secretRepository: SecretRepository | |
| ) { | |
| fun notify( | |
| notificationRequest: NotificationRequest, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Service | |
| class NotificationService( | |
| private val restClient: TwilioRestClient, | |
| private val secretRepository: SecretRepository | |
| ) { | |
| fun notify( | |
| notificationRequest: NotificationRequest, | |
| // Now we know its type | |
| creator: (PhoneNumber, String, String) -> MessageCreator | |
| ): NotificationResponse { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Message { | |
| // ... | |
| public static MessageCreator creator(final com.twilio.type.PhoneNumber to, | |
| final String messagingServiceSid, | |
| final String body) { | |
| return new MessageCreator(to, messagingServiceSid, body); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Service | |
| class NotificationService( | |
| private val restClient: TwilioRestClient, | |
| private val secretRepository: SecretRepository | |
| ) { | |
| fun notify( | |
| notificationRequest: NotificationRequest, | |
| // Inject creator function as an argument | |
| creator: ???? | |
| ): NotificationResponse { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // while executing in Spring context. | |
| // Dependencies in constructor are injected by Spring | |
| @Service | |
| class NotificationService( | |
| private val restClient: TwilioRestClient, | |
| private val secretRepository: SecretRepository | |
| ) { | |
| fun notify(notificationRequest: NotificationRequest): NotificationResponse { | |
| val (countryCode, phoneNumber, text) = notificationRequest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Service | |
| class OtpLoginService( | |
| private val otpService: OtpService, | |
| private val otpAuthProvider: OtpAuthProvider | |
| ) { | |
| fun login(otpVerificationRequest: OtpVerificationRequest): VerificationResult { | |
| // ***** calls static method | |
| val securityContext = SecurityContextHolder.getContext() | |
| val verification = otpService.verifyOTP(otpVerificationRequest) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data Maybe a = Just a | Nothing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fmap length Nothing | |
| -- Nothing | |
| fmap length (Just "Hello") | |
| -- Just 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [1,2,3,4].map(x => x + 1) | |
| // [2,3,4,5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fmap (+1) [1,2,3,4] | |
| -- [2,3,4,5] |