{-# LANGUAGE Safe #-} {- arch-tag: Maybe utilities Copyright (c) 2005-2011 John Goerzen <jgoerzen@complete.org> All rights reserved. For license and copyright information, see the file LICENSE -} {- | Module : Data.Maybe.Utils Copyright : Copyright (C) 2005-2011 John Goerzen SPDX-License-Identifier: BSD-3-Clause Stability : stable Portability: portable Utilities for working with the Either data type -} module Data.Maybe.Utils ( forceMaybe, forceMaybeMsg ) where {- | Pulls a Just value out of a Maybe value. If the Maybe value is Nothing, raises an exception with error. -} forceMaybe :: Maybe a -> a forceMaybe :: forall a. Maybe a -> a forceMaybe = String -> Maybe a -> a forall a. String -> Maybe a -> a forceMaybeMsg String "forceMaybe: Got Nothing" {- | Like 'forceMaybe', but lets you customize the error message raised if Nothing is supplied. -} forceMaybeMsg :: String -> Maybe a -> a forceMaybeMsg :: forall a. String -> Maybe a -> a forceMaybeMsg String msg Maybe a Nothing = String -> a forall a. HasCallStack => String -> a error String msg forceMaybeMsg String _ (Just a x) = a x