relude-0.6.0.0: Custom prelude from Kowainik
Copyright(c) 2016 Stephen Diehl
(c) 2016-2018 Serokell
(c) 2018-2019 Kowainik
LicenseMIT
MaintainerKowainik <xrom.xkov@gmail.com>
Safe HaskellUnsafe
LanguageHaskell2010

Relude.Unsafe

Description

Unsafe functions to work with lists and Maybe. Sometimes unavoidable but it's better not to use them. This module is intended to be imported qualified and it's not even included in default prelude exports.

import qualified Relude.Unsafe as Unsafe

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

Documentation

(!!) :: [a] -> Int -> a infixl 9 #

List index (subscript) operator, starting from 0. It is an instance of the more general genericIndex, which takes an index of any integral type.

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

O(n). Return all the elements of a list except the last one. The list must be non-empty.

last :: [a] -> a #

O(n). Extract the last element of a list, which must be finite and non-empty.

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

O(1). Extract the elements after the head of a list, which must be non-empty.

head :: [a] -> a #

O(1). Extract the first element of a list, which must be non-empty.

fromJust :: HasCallStack => Maybe a -> a #

The fromJust function extracts the element out of a Just and throws an error if its argument is Nothing.

Examples

Expand

Basic usage:

>>> fromJust (Just 1)
1
>>> 2 * (fromJust (Just 10))
20
>>> 2 * (fromJust Nothing)
*** Exception: Maybe.fromJust: Nothing

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 usefull when used in a partially applied position like:

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