| Copyright | (c) digitally induced GmbH 2020 |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
IHP.HaskellSupport
Contents
Description
Synopsis
- (|>) :: a -> (a -> b) -> b
- (|>>) :: Functor f => f a -> (a -> b) -> f b
- whenEmpty :: (Applicative f, IsEmpty value) => value -> f () -> f ()
- whenNonEmpty :: (IsEmpty a, Applicative f) => a -> f () -> f ()
- get :: forall model (name :: Symbol) value. (KnownSymbol name, HasField name model value) => Proxy name -> model -> value
- set :: forall model (name :: Symbol) value. (KnownSymbol name, SetField name model value) => Proxy name -> value -> model -> model
- setJust :: forall model (name :: Symbol) value. (KnownSymbol name, SetField name model (Maybe value)) => Proxy name -> value -> model -> model
- setMaybe :: forall model (name :: Symbol) value. (KnownSymbol name, SetField name model (Maybe value)) => Proxy name -> Maybe value -> model -> model
- ifOrEmpty :: Monoid a => Bool -> a -> a
- modify :: forall model (name :: Symbol) value. (KnownSymbol name, HasField name model value, SetField name model value) => Proxy name -> (value -> value) -> model -> model
- modifyJust :: forall model (name :: Symbol) value. (KnownSymbol name, HasField name model (Maybe value), SetField name model (Maybe value)) => Proxy name -> (value -> value) -> model -> model
- class SetField (field :: Symbol) model value | field model -> value where
- setField :: value -> model -> model
- class HasField field model value => UpdateField (field :: Symbol) model model' value value' | model model' value' -> value where
- updateField :: value' -> model -> model'
- incrementField :: forall model (name :: Symbol) value. (KnownSymbol name, HasField name model value, SetField name model value, Num value) => Proxy name -> model -> model
- decrementField :: forall model (name :: Symbol) value. (KnownSymbol name, HasField name model value, SetField name model value, Num value) => Proxy name -> model -> model
- isToday :: UTCTime -> IO Bool
- isToday' :: UTCTime -> UTCTime -> Bool
- forEach :: (MonoFoldable mono, Applicative m) => mono -> (Element mono -> m ()) -> m ()
- forEachWithIndex :: Monad m => [a] -> ((Int, a) -> m ()) -> m ()
- textToInt :: Text -> Maybe Int
- isWeekend :: Day -> Bool
- todayIsWeekend :: IO Bool
- debug :: Show value => value -> value
- includes :: (MonoFoldable container, Eq (Element container)) => Element container -> container -> Bool
- stripTags :: Text -> Text
- symbolToText :: forall (symbol :: Symbol). KnownSymbol symbol => Text
- symbolToByteString :: forall (symbol :: Symbol). KnownSymbol symbol => ByteString
- class IsEmpty value where
- copyFields :: CopyFields fields destinationRecord sourceRecord => sourceRecord -> destinationRecord -> destinationRecord
- allEnumValues :: Enum enumType => [enumType]
Documentation
whenEmpty :: (Applicative f, IsEmpty value) => value -> f () -> f () Source #
whenNonEmpty :: (IsEmpty a, Applicative f) => a -> f () -> f () Source #
get :: forall model (name :: Symbol) value. (KnownSymbol name, HasField name model value) => Proxy name -> model -> value Source #
Returns the field value for a field name
set :: forall model (name :: Symbol) value. (KnownSymbol name, SetField name model value) => Proxy name -> value -> model -> model Source #
Sets a field of a record and returns the new record.
setJust :: forall model (name :: Symbol) value. (KnownSymbol name, SetField name model (Maybe value)) => Proxy name -> value -> model -> model Source #
setMaybe :: forall model (name :: Symbol) value. (KnownSymbol name, SetField name model (Maybe value)) => Proxy name -> Maybe value -> model -> model Source #
modify :: forall model (name :: Symbol) value. (KnownSymbol name, HasField name model value, SetField name model value) => Proxy name -> (value -> value) -> model -> model Source #
modifyJust :: forall model (name :: Symbol) value. (KnownSymbol name, HasField name model (Maybe value), SetField name model (Maybe value)) => Proxy name -> (value -> value) -> model -> model Source #
Like modify, but only modifies the value if it's not Nothing.
class SetField (field :: Symbol) model value | field model -> value where Source #
Instances
class HasField field model value => UpdateField (field :: Symbol) model model' value value' | model model' value' -> value where Source #
Methods
updateField :: value' -> model -> model' Source #
incrementField :: forall model (name :: Symbol) value. (KnownSymbol name, HasField name model value, SetField name model value, Num value) => Proxy name -> model -> model Source #
Plus 1 on record field.
decrementField :: forall model (name :: Symbol) value. (KnownSymbol name, HasField name model value, SetField name model value, Num value) => Proxy name -> model -> model Source #
Minus 1 on a record field.
forEach :: (MonoFoldable mono, Applicative m) => mono -> (Element mono -> m ()) -> m () Source #
Example:
forEach users \user -> putStrLn (tshow user)
Example: Within HSX
renderUser :: User -> Html
renderUser user = [hsx|<div>User: {user.name}</div>|]
render = [hsx|{forEach users renderUser}|]forEachWithIndex :: Monad m => [a] -> ((Int, a) -> m ()) -> m () Source #
Like forEach but with an index, starting at 0
Example: With a Callback
forEachWithIndex users \(index, user) -> putStrLn (tshow index <> ": " <> tshow user)
Example: With a Function
printUser :: (Int, User) -> IO () printUser (index, user) = putStrLn (tshow index <> ": " <> tshow user) forEachWithIndex users printUser
Example: Within HSX
renderUser :: (Int, User) -> Html
renderUser (index, user) = [hsx|<div>User {index}: {user.name}</div>|]
render = [hsx|{forEachWithIndex users renderUser}|]textToInt :: Text -> Maybe Int Source #
Parses a text to an int. Returns Nothing on failure.
Example:
>>>textToInt "1337"Just 1337
>>>textToInt "bad input"Nothing
isWeekend :: Day -> Bool Source #
Returns True when day is Saturday or Sunday.
Example:
>>>isWeekend $ fromGregorian 2019 10 7False
>>>isWeekend $ fromGregorian 2020 6 13True
todayIsWeekend :: IO Bool Source #
Returns True when today is Saturday or Sunday.
Example:
do
todayIsWeekend <- isWeekend
when todayIsWeekend (putStrLn "It's weekend!")debug :: Show value => value -> value Source #
Debug-print a value during evaluation
Alias for traceShowId
includes :: (MonoFoldable container, Eq (Element container)) => Element container -> container -> Bool Source #
stripTags :: Text -> Text Source #
Removes all html tags from a given html text
>>>stripTags "This is <b>Bold</b>""This is Bold"
symbolToText :: forall (symbol :: Symbol). KnownSymbol symbol => Text Source #
Returns the value of a type level symbol as a text
>>>symbolToText @"hello""hello"
>>>symbolToText @(GetTableName User)"users"
symbolToByteString :: forall (symbol :: Symbol). KnownSymbol symbol => ByteString Source #
Returns the value of a type level symbol as a bytestring
>>>symbolToByteString @"hello""hello"
>>>symbolToByteString @(GetTableName User)"users"
class IsEmpty value where Source #
Used by nonEmpty and isEmptyValue to check for emptyness
Methods
isEmpty :: value -> Bool Source #
Returns True when the value is an empty string, empty list, zero UUID, etc.
copyFields :: CopyFields fields destinationRecord sourceRecord => sourceRecord -> destinationRecord -> destinationRecord Source #
allEnumValues :: Enum enumType => [enumType] Source #
Returns a list of all values of an enum type
Given a data structure like this:
data Color = Yellow | Red | Blue deriving (Enum)
You can call allEnumValues to get a list of all colors:
>>>allEnumValues @Color[Yellow, Red, Blue]
This also works if the enum is defined in the Schema.sql:
CREATE TYPE brokerage_subscription_type AS ENUM ('basic_subscription', 'bronze_subscription', 'silver_subscription', 'gold_subscription');>>>allEnumValues @BrokerageSubscriptionType[BasicSubscription, BronzeSubscription, SilverSubscription]
Orphan instances
| Default UUID Source # | |
| IsString UUID Source # | |
Methods fromString :: String -> UUID # | |
| ConvertibleStrings ByteString Key Source # | |
Methods convertString :: ByteString -> Key Source # | |
| ConvertibleStrings Text Key Source # | |
Methods convertString :: Text -> Key Source # | |
| (KnownSymbol name, name' ~ name) => IsLabel name (Proxy name') Source # | |
| IsString string => IsString (Maybe string) Source # | Allows `Just "someThing"` to be written as `"someThing"` |
Methods fromString :: String -> Maybe string # | |