Module

Webb.Monad.Prelude

Package
purescript-webb-monad
Repository
mitchellandwebb/webb-monad

#showEffect Source

showEffect :: forall a. Show a => Effect a -> String

#andM Source

andM :: forall m. Monad m => m Boolean -> m Boolean -> m Boolean

#orM Source

orM :: forall m. Monad m => m Boolean -> m Boolean -> m Boolean

#notM Source

notM :: forall m. Functor m => m Boolean -> m Boolean

#(&&=) Source

Operator alias for Webb.Monad.Prelude.andM (right-associative / precedence 3)

#(||=) Source

Operator alias for Webb.Monad.Prelude.orM (right-associative / precedence 2)

#timesRepeat Source

timesRepeat :: forall m a. Monad m => Int -> m a -> m (Array a)

#timesRepeat_ Source

timesRepeat_ :: forall m. Monad m => Int -> m Unit -> m Unit

#forceEither Source

forceEither :: forall m a. MonadThrow Error m => Either String a -> m a

#forceMaybe Source

forceMaybe :: forall m a. MonadThrow Error m => Maybe a -> m a

#forceMaybe' Source

forceMaybe' :: forall m a. MonadThrow Error m => String -> Maybe a -> m a

#onCancel Source

onCancel :: forall a. Aff Unit -> Aff a -> Aff a

#throwString Source

throwString :: forall a m. MonadThrow Error m => String -> m a

#launch Source

launch :: forall a m. MonadEffect m => Aff a -> m (Fiber a)

#launch_ Source

launch_ :: forall m. MonadEffect m => Aff Unit -> m Unit

#kill Source

kill :: forall m a. MonadAff m => Fiber a -> m Unit

#_kill Source

_kill :: forall m a. MonadAff m => Fiber a -> m Unit

#delayInt Source

delayInt :: forall m. MonadAff m => Int -> m Unit

#expectSatisfy Source

expectSatisfy :: forall m a. MonadThrow Error m => Show a => a -> (a -> Boolean) -> String -> m Unit

#expectSatisfyM Source

expectSatisfyM :: forall m a. MonadThrow Error m => Show a => a -> (a -> m Boolean) -> String -> m Unit

#expectNotSatisfyM Source

expectNotSatisfyM :: forall m a. MonadThrow Error m => Show a => a -> (a -> m Boolean) -> String -> m Unit

#expectM Source

expectM :: forall m. MonadEffect m => m Boolean -> String -> m Unit

#spyM Source

spyM :: forall m a. Warn (Text "Debug function usage") => Monad m => m a -> m a

#expect Source

expect :: forall m. MonadEffect m => Boolean -> String -> m Unit

Re-exports from Debug

#DebugWarning Source

class DebugWarning 

Nullary class used to raise a custom warning for the debug functions.

Instances

#traceTime Source

traceTime :: forall a. DebugWarning => String -> (Unit -> a) -> a

Measures the time it takes the given function to run and prints it out, then returns the function's result. This is handy for diagnosing performance problems by wrapping suspected parts of the code in traceTime.

For example:

bunchOfThings =
  [ traceTime "one" \_ -> one x y
  , traceTime "two" \_ -> two z
  , traceTime "three" \_ -> three a b c
  ]

Console output would look something like this:

one took 3.456ms
two took 562.0023ms
three took 42.0111ms

Note that the timing precision may differ depending on whether the Performance API is supported. Where supported (on most modern browsers and versions of Node), the Performance API offers timing resolution of 5 microseconds. Where Performance API is not supported, this function will fall back on standard JavaScript Date object, which only offers a 1-millisecond resolution.

#traceM Source

traceM :: forall m a. DebugWarning => Monad m => a -> m Unit

Log any PureScript value to the console and return the unit value of the Monad m.

#trace Source

trace :: forall a b. DebugWarning => a -> (Unit -> b) -> b

Log any PureScript value to the console for debugging purposes and then return a value. This will log the value's underlying representation for low-level debugging, so it may be desireable to show the value first.

The return value is thunked so it is not evaluated until after the message has been printed, to preserve a predictable console output.

For example:

doSomething = trace "Hello" \_ -> ... some value or computation ...

#spyWith Source

spyWith :: forall a b. DebugWarning => String -> (a -> b) -> a -> a

Similar to spy, but allows a function to be passed in to alter the value that will be printed. Useful in cases where the raw printed form of a value is inconvenient to read - for example, when spying on a Set, passing Array.fromFoldable here will print it in a more useful form.

#spy Source

spy :: forall a. DebugWarning => String -> a -> a

Logs any value and returns it, using a "tag" or key value to annotate the traced value. Useful when debugging something in the middle of a expression, as you can insert this into the expression without having to break it up.

#debugger Source

debugger :: forall a. DebugWarning => (Unit -> a) -> a

Triggers any available debugging features in the current runtime - in a web browser with the debug tools open, this acts like setting a breakpoint in the script. If no debugging feature are available nothing will occur, although the passed contination will still be evaluated.

Generally this works best by passing in a block of code to debug as the continuation argument, as stepping forward in the debugger will then drop straight into the passed code block.