Skip to content

Instantly share code, notes, and snippets.

View teivah's full-sized avatar
Current status: Building a newsletter (The Coder Cafe)

Teiva Harsanyi teivah

Current status: Building a newsletter (The Coder Cafe)
View GitHub Profile
class Foo {
}
@teivah
teivah / 28.java
Last active September 1, 2024 21:21
if ((((notification.orderID == orderID)
|| (notification.customerID == customerID)
|| (eventIDs.contains(notification.eventID)) && (notification.type.toAllStaff || notification.type.toAllOrders))
|| (isAdmin && eventIDs.contains(notification.eventID))
&& (userID != notification.senderID || notification.senderID == null))) {
send(notification);
}
//
plusOne :: Maybe (Int -> Int)
plusOne = Just (+ 1)
plusOne :: Int -> Maybe Int
plusOne x = Just (x + 1)
plusOne :: Int -> Int
plusOne x = x + 1
withMonad :: Int -> String -> Maybe String
withMonad age name = do
validateAge age
s <- return (greet name)
return (greet s) -- Just "Hello Hello John"
withMonad :: Int -> String -> Maybe String
withMonad age name = do
validateAge age
return (greet name)
withMonad :: Int -> String -> Maybe String
withMonad age name = validateAge age >>= \_ -> return (greet name)
withApplicative :: Int -> String -> Maybe String
withApplicative age name = greet <$> (Just name) <*> validateAge age
validateAge :: Int -> Maybe Int
validateAge age
| age >= 18 = return age
| otherwise = Nothing
greet :: String -> String
greet name = "Hello " ++ name