Skip to content

Instantly share code, notes, and snippets.

// 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,
@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 {
class Message {
// ...
public static MessageCreator creator(final com.twilio.type.PhoneNumber to,
final String messagingServiceSid,
final String body) {
return new MessageCreator(to, messagingServiceSid, body);
}
}
@Service
class NotificationService(
private val restClient: TwilioRestClient,
private val secretRepository: SecretRepository
) {
fun notify(
notificationRequest: NotificationRequest,
// Inject creator function as an argument
creator: ????
): NotificationResponse {
// 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
@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)
data Maybe a = Just a | Nothing
fmap length Nothing
-- Nothing
fmap length (Just "Hello")
-- Just 5
[1,2,3,4].map(x => x + 1)
// [2,3,4,5]
@iboss-ptk
iboss-ptk / ListExample.hs
Last active June 29, 2018 23:51
functor
fmap (+1) [1,2,3,4]
-- [2,3,4,5]