relude-1.2.1.0: Safe, performant, user-friendly and lightweight Haskell Standard Library
Copyright(c) 2016 Stephen Diehl
(c) 2016-2018 Serokell
(c) 2018-2023 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
StabilityStable
PortabilityPortable
Safe HaskellUnsafe
LanguageHaskell2010

Relude.Unsafe

Description

⚠️ Warning ⚠️

This module contains unsafe partial functions. They are unavoidable sometimes, but we encourage you to use safer analogues:

PartialTotal
head :: [a] -> ahead :: NonEmpty a -> a
tail :: [a] -> [a]tail :: NonEmpty a -> [a]
read :: Read a => String -> areadMaybe :: Read a => String -> Maybe a
fromJust :: Maybe a -> afromMaybe :: a -> Maybe a -> a

This module is intended to be imported qualified and it is not included in default prelude exports.

import qualified Relude.Unsafe as Unsafe

foo :: [a] -> a
foo = Unsafe.head
Synopsis

Unsafe list functions

head :: HasCallStack => [a] -> a #

tail :: HasCallStack => [a] -> [a] #

last :: HasCallStack => [a] -> a #

init :: HasCallStack => [a] -> [a] #

(!!) :: HasCallStack => [a] -> Int -> a #

at :: Int -> [a] -> a Source #

Similar to !! but with flipped arguments. get element from list using index value starting from `0`.

>>> at 2 ["a", "b", "c"]
"c"

it is also useful when used in a partially applied position like:

>>> map (at 1) [["a","b","c"], ["a","b","c"], ["a","b","c"]]
["b","b","b"]

Unsafe Maybe functions

Unsafe Text.Read functions

read :: Read a => String -> a #