-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
280 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{-# LANGUAGE CPP #-} | ||
|
||
#if MIN_VERSION_base(4,20,0) | ||
{-# OPTIONS_GHC -Wno-x-partial #-} | ||
#endif | ||
|
||
|
||
-- | | ||
-- Module: unsafe.Data.Foldable.Unsafe | ||
-- Copyright: Copyright © 2024 Kadena LLC. | ||
-- License: MIT | ||
-- Maintainer: Pact Team | ||
-- Stability: experimental | ||
-- | ||
-- This module provides unsafe versions for all functions in "Data.Foldable" | ||
-- that are either partial or return a 'Maybe' value. | ||
-- | ||
module Data.Foldable.Unsafe | ||
( | ||
-- * Unsafe versions of partial functions | ||
unsafeMaximum | ||
, unsafeMaximumBy | ||
, unsafeMinimum | ||
, unsafeMinimumBy | ||
|
||
-- * Unsafe versions of functions that return 'Maybe' values | ||
, unsafeFind | ||
) where | ||
|
||
import Data.Foldable | ||
|
||
import GHC.Stack | ||
|
||
-- -------------------------------------------------------------------------- -- | ||
-- Unsafe versions of partial functions | ||
|
||
unsafeMaximum :: HasCallStack => Foldable t => Ord a => t a -> a | ||
unsafeMaximum = maximum | ||
|
||
unsafeMaximumBy :: HasCallStack => Foldable t => (a -> a -> Ordering) -> t a -> a | ||
unsafeMaximumBy = maximumBy | ||
|
||
unsafeMinimum :: HasCallStack => (Foldable t, Ord a) => t a -> a | ||
unsafeMinimum = minimum | ||
|
||
unsafeMinimumBy :: HasCallStack => Foldable t => (a -> a -> Ordering) -> t a -> a | ||
unsafeMinimumBy = minimumBy | ||
|
||
-- -------------------------------------------------------------------------- -- | ||
-- Unsafe versions of functions that return Maybe | ||
|
||
unsafeFind :: HasCallStack => Foldable t => (a -> Bool) -> t a -> a | ||
unsafeFind a b = case find a b of | ||
Nothing -> error "Data.List.Unsafe.unsafeFind: not found" | ||
Just x -> x | ||
|
Oops, something went wrong.