ja-base-extra-0.2.1.0: Extra functions I require in base

Copyright(c) Justus Adam, 2015
LicenseBDS3
Maintainerdev@justus.science
Stabilityexperimental
PortabilityPOSIX, Windows
Safe HaskellSafe
LanguageHaskell2010

Data.List.JAExtra

Contents

Description

 

Synopsis

Reading values

get :: Int -> [α] -> Maybe α Source

The function that !! should be.

The get function attempts to extract the element at the specified index from the list, but instead of failing with an error returns a Maybe value.

>>> get 0 [1, 2, 3]
Just 1
>>> get 2 [1, 2, 3]
Just 3
>>> get 3 [1, 2, 3]
Nothing

This function also accepts negative indexes, taking elements from the back of the list, aka get (-1) is the last element of the list and get (-2) the second to last. Both positive and negative indexes are subject to boundary checks.

>>> get -1 [1, 2, 3]
Just 3
>>> get -4 [1, 2, 3]
Nothing

For infinite lists using negative indexes is _|_ (does not terminate). Positive indexes do however do work with infinite lists.

Modifying lists

slice :: Int -> Int -> [α] -> [α] Source

slice i j extracts a sublist from index i up to, but not including, j.

This function also accepts negative indexes which, again, are _|_ for infinite lists.

>>> slice 1 3 [1, 2, 3, 4, 5]
[2, 3]

The index rules are the same as with get.

Tuple conversions

"toNTuple" functions match whether a list contains only N elements yielding an N-Tuple containing those elements.

This can for example also be used to extract elements from a section of the list as a Tuple like so:

to3Tuple . take 3

to1Value :: [α] -> Maybe α Source

Completeness function that converts a singleton list into its only contained value.

This function is the single value version of the "toNTuple" function family.

to2Tuple :: [α] -> Maybe (α, α) Source

to3Tuple :: [α] -> Maybe (α, α, α) Source

to4Tuple :: [α] -> Maybe (α, α, α, α) Source

to5Tuple :: [α] -> Maybe (α, α, α, α, α) Source

to6Tuple :: [α] -> Maybe (α, α, α, α, α, α) Source

to7Tuple :: [α] -> Maybe (α, α, α, α, α, α, α) Source

to8Tuple :: [α] -> Maybe (α, α, α, α, α, α, α, α) Source

to9Tuple :: [α] -> Maybe (α, α, α, α, α, α, α, α, α) Source

to10Tuple :: [α] -> Maybe (α, α, α, α, α, α, α, α, α, α) Source

Zipping lists

Zipping functions that do not stop when the shorter lists expire but when the longer lists do.

Zipping to Maybe

The fillZipN function family takes N lists and returns a list of N-tuples.

Unlike zip fillZip does not stop when one of the lists is empty, but keeps going inserting Nothing for the missing values in the shorter lists.

fillZip :: [α] -> [β] -> [(Maybe α, Maybe β)] Source

Alias for fillZip2.

fillZip2 :: [α] -> [β] -> [(Maybe α, Maybe β)] Source

fillZip3 :: [α] -> [β] -> [γ] -> [(Maybe α, Maybe β, Maybe γ)] Source

fillZip4 :: [α] -> [β] -> [γ] -> [δ] -> [(Maybe α, Maybe β, Maybe γ, Maybe δ)] Source

fillZip5 :: [α] -> [β] -> [γ] -> [δ] -> [ζ] -> [(Maybe α, Maybe β, Maybe γ, Maybe δ, Maybe ζ)] Source

Zipping Monoids

The monoidFillZipN function family takes N lists and returns a list of N-tuples.

Unlike zip, monoidFillZip does not stop when one of the lists is empty, but keeps going inserting mempty for the missing values in the shorter lists.

monoidFillZip :: (Monoid α, Monoid β) => [α] -> [β] -> [(α, β)] Source

Alias for monoidFillZip2.

monoidFillZip2 :: (Monoid α, Monoid β) => [α] -> [β] -> [(α, β)] Source

monoidFillZip3 :: (Monoid α, Monoid β, Monoid γ) => [α] -> [β] -> [γ] -> [(α, β, γ)] Source

monoidFillZip4 :: (Monoid α, Monoid β, Monoid γ, Monoid δ) => [α] -> [β] -> [γ] -> [δ] -> [(α, β, γ, δ)] Source

monoidFillZip5 :: (Monoid α, Monoid β, Monoid γ, Monoid δ, Monoid ζ) => [α] -> [β] -> [γ] -> [δ] -> [ζ] -> [(α, β, γ, δ, ζ)] Source