Copyright(c) digitally induced GmbH 2020
Safe HaskellNone

IHP.HaskellSupport

Description

 
Synopsis

Documentation

(|>) :: t1 -> (t1 -> t2) -> t2 infixl 8 Source #

isEmpty :: MonoFoldable value => value -> Bool Source #

whenEmpty :: (Applicative f, MonoFoldable value) => value -> f () -> f () Source #

whenNonEmpty :: (MonoFoldable a, Applicative f) => a -> f () -> f () Source #

get :: forall model name value. (KnownSymbol name, HasField name model value) => Proxy name -> model -> value Source #

Returns the field value for a field name

Example:

data Project = Project { name :: Text, isPublic :: Bool }

let project = Project { name = "Hello World", isPublic = False }
>>> get #name project
"Hello World"
>>> get #isPublic project
False

set :: forall model name value. (KnownSymbol name, SetField name model value) => Proxy name -> value -> model -> model Source #

Sets a field of a record and returns the new record.

Example:

data Project = Project { name :: Text, isPublic :: Bool }

let project = Project { name = "Hello World", isPublic = False }
>>> set #name "New Name" project
Project { name = "New Name", isPublic = False }
>>> set #isPublic True project
Project { name = "Hello World", isPublic = True }

ifOrEmpty :: Monoid a => Bool -> a -> a Source #

modify :: forall model name value updateFunction. (KnownSymbol name, HasField name model value, SetField name model value) => Proxy name -> (value -> value) -> model -> model Source #

class SetField (field :: Symbol) model value | field model -> value where Source #

Methods

setField :: value -> model -> model Source #

Instances

Instances details
SetField "annotations" MetaBag [(Text, Text)] Source # 
Instance details

Defined in IHP.ModelSupport

Methods

setField :: [(Text, Text)] -> MetaBag -> MetaBag Source #

SetField "touchedFields" MetaBag [Text] Source # 
Instance details

Defined in IHP.ModelSupport

Methods

setField :: [Text] -> MetaBag -> MetaBag Source #

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 value. (KnownSymbol name, HasField name model value, SetField name model value, Num value) => Proxy name -> model -> model Source #

Plus 1 on record field.

Example:

data Project = Project { name :: Text, followersCount :: Int }

let project = Project { name = "Hello World", followersCount = 0 }
>>> project |> incrementField #followersCount
Project { name = "Hello World", followersCount = 1 }

decrementField :: forall model name value. (KnownSymbol name, HasField name model value, SetField name model value, Num value) => Proxy name -> model -> model Source #

Minus 1 on a record field.

Example:

data Project = Project { name :: Text, followersCount :: Int }

let project = Project { name = "Hello World", followersCount = 1337 }
>>> project |> decrementField #followersCount
Project { name = "Hello World", followersCount = 1336 }

forEach :: (MonoFoldable mono, Applicative m) => mono -> (Element mono -> m ()) -> m () Source #

Example: forEach users user -> putStrLn (tshow user)

forEachWithIndex :: Applicative m => [a] -> ((Int, a) -> m ()) -> m () Source #

Example: forEachWithIndex users (index, user) -> putStrLn (tshow user)

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 7
False
>>> isWeekend $ fromGregorian 2020 6 13
True

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. KnownSymbol symbol => Text Source #

Returns the value of a type level symbol as a text

>>> symbolToText @"hello"
"hello"
>>> symbolToText @(GetTableName User)
"users"

Orphan instances

Default UUID Source # 
Instance details

Methods

def :: UUID #

(KnownSymbol name, name' ~ name) => IsLabel name (Proxy name') Source # 
Instance details

Methods

fromLabel :: Proxy name' #

IsString string => IsString (Maybe string) Source #

Allows `Just "someThing"` to be written as `"someThing"`

Instance details

Methods

fromString :: String -> Maybe string #