ilist: Optimised list functions for doing index-related things

[ library, list, mpl ] [ Propose Tags ]

Optimised list functions for doing index-related things. They're faster than common idioms in all cases, they avoid space leaks, and sometimes they fuse better as well.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.3.1.0, 0.4.0.0, 0.4.0.1
Change log CHANGELOG.md
Dependencies base (>=4.10 && <4.20) [details]
License MPL-2.0
Copyright 2016-2019 Artyom Kazak (BSD-3-Clause) 2019-2020 Kowainik (MPL-2.0)
Author Artyom
Maintainer Kowainik <xrom.xkov@gmail.com>
Revised Revision 3 made by Bodigrim at 2023-08-06T18:57:33Z
Category List
Home page http://github.com/kowainik/ilist
Bug tracker http://github.com/kowainik/ilist/issues
Source repo head: git clone https://github.com/kowainik/ilist.git
Uploaded by shersh at 2020-05-07T17:40:16Z
Distributions Fedora:0.4.0.1, LTSHaskell:0.4.0.1, NixOS:0.4.0.1, Stackage:0.4.0.1, openSUSE:0.4.0.1
Reverse Dependencies 16 direct, 3 indirect [details]
Downloads 9343 total (60 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for ilist-0.4.0.1

[back to package description]

ilist

GitHub CI AppVeyor Hackage Stackage LTS Stackage Nightly MPL-2.0 license

What is this

This is a library with lots of list functions that are related to indices. It has often-reinvented deleteAt, setAt, etc, as well as indexed variants of functions from Data.List (e.g. imap, ifilter, izipWith). It has no dependencies, builds in about a second, and works on GHC from 7.4 to 8.0; the functions are optimised and benchmarked (for instance, the zip [0..] idiom is usually twice as slow, and sometimes 20× as slow).

So, this library is intended to be the canonical place for index-related functions. You are encouraged to depend on this library instead of reinventing the functions, using zip [0..], or using lens when all you need is a simple imap or ifoldr (not to mention that lens variants are usually 2–10 times slower for lists).

Why should you care

You shouldn't, actually. This is a small library, it won't change anyone's life, and if you care about speed you probably shouldn't be using lists anyway (unless you keep your fingers crossed and hope that fusion will kick in). So, consider it more of a public service announcement – “hey, just in case you ever need them, index-related functions live here”.

Usage

Unfortunately, Data.List.Indexed was taken by IndexedList, which implements such exciting things as “counted lists” and “conic lists”. Nope, I'm not bitter at all. Okay, maybe a bit, even tho it's completely unfair to IndexedList. Anyway:

import Data.List.Index

And you can use functions from Data.List by prepending i to them. There's also indexed :: [a] -> [(Int,a)] and a family of functions for modifying the element at an index (deleteAt, setAt, modifyAt, updateAt, insertAt).

Watch out – ifoldl has the index as the second parameter of the function:

ifoldl :: (b -> Int -> a -> b) -> b -> [a] -> b

That's the same convention that containers and vector use. Other functions pass the index as the first argument, as expected.