mod -package:base

Not on Stackage, so not searched. Fast type-safe modular arithmetic
pattern synonym for remainder %
pattern synonym for remainder %
A different MonadError analogue to the withExceptT function. Modify the value (and possibly the type) of an error in an ExceptT-transformed monad, while stripping the ExceptT layer. This is useful for adapting the MonadError constraint of a computation. For example:
data DatabaseError = ...

performDatabaseQuery :: (MonadError DatabaseError m, ...) => m PersistedValue

data AppError
= MkDatabaseError DatabaseError
| ...

app :: (MonadError AppError m, ...) => m ()
Given these types, performDatabaseQuery cannot be used directly inside app, because the error types don't match. Using modifyError, an equivalent function with a different error type can be constructed:
performDatabaseQuery' :: (MonadError AppError m, ...) => m PersistedValue
performDatabaseQuery' = modifyError MkDatabaseError performDatabaseQuery
Since the error types do match, performDatabaseQuery' _can_ be used in app, assuming all other constraints carry over. This works by instantiating the m in the type of performDatabaseQuery to ExceptT DatabaseError m', which satisfies the MonadError DatabaseError constraint. Immediately, the ExceptT DatabaseError layer is unwrapped, producing Either a DatabaseError or a PersistedValue. If it's the former, the error is wrapped in MkDatabaseError and re-thrown in the inner monad, otherwise the result value is returned.
Monadic state transformer. Maps an old state to a new state inside a state monad. The old state is thrown away.
Main> :t modify ((+1) :: Int -> Int)
modify (...) :: (MonadState Int a) => a ()
This says that modify (+1) acts over any Monad that is a member of the MonadState class, with an Int state.
A variant of modify in which the computation is strict in the new state.
modify f is an action that updates the state to the result of applying f to the current state.
modify f is an action that updates the state to the result of applying f to the current state.
modify f is an action that updates the state to the result of applying f to the current state.
A variant of modify in which the computation is strict in the new state.
A variant of modify in which the new state is generated by a monadic action.
A variant of modify in which the computation is strict in the new state. Note that this is only strict in the top level of the state. Lazy components of the state will not be evaluated unless f evaluates them.
Apply a destructive operation to a vector. The operation may be performed in place if it is safe to do so and will modify a copy of the vector otherwise (see New for details).

Examples

>>> import qualified Data.Vector as V

>>> import qualified Data.Vector.Mutable as MV

>>> V.modify (\v -> MV.write v 0 'x') $ V.replicate 4 'a'
"xaaa"
Apply a destructive operation to a vector. The operation may be performed in place if it is safe to do so and will modify a copy of the vector otherwise (see New for details).

Examples

>>> import qualified Data.Vector.Strict as V

>>> import qualified Data.Vector.Strict.Mutable as MV

>>> V.modify (\v -> MV.write v 0 'x') $ V.replicate 4 'a'
"xaaa"
Modify the element at the given position.
Modify the element at the given position using a monadic function.
Modify the element at the given position.
Modify the element at the given position using a monadic function.
Apply a destructive operation to a vector. The operation may be performed in place if it is safe to do so and will modify a copy of the vector otherwise (see New for details).

Examples

>>> import qualified Data.Vector.Primitive as VP

>>> import qualified Data.Vector.Primitive.Mutable as MVP

>>> VP.modify (\v -> MVP.write v 0 'x') $ VP.replicate 4 'a'
"xaaa"
Modify the element at the given position.