ilist

Optimised list functions for doing index-related things

http://github.com/kowainik/ilist

Version on this page:0.4.0.1@rev:1
LTS Haskell 22.39:0.4.0.1@rev:3
Stackage Nightly 2024-10-31:0.4.0.1@rev:3
Latest on Hackage:0.4.0.1@rev:3

See all snapshots ilist appears in

MPL-2.0 licensed by Artyom
Maintained by Kowainik
This version can be pinned in stack with:ilist-0.4.0.1@sha256:1e7ab6cf03efac20bfe68dbc9ba3f9c3103f0f0ce6645e6c325cc50963bc256d,3270

Module documentation for 0.4.0.1

Depends on 1 package(full list with versions):

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.

Changes

Changelog

ilist uses PVP Versioning. The changelog is available on GitHub.

0.4.0.1 — May 7, 2020

  • #7: Support GHC-8.10. Move from GHC-8.8.1 support to GHC-8.8.3.

0.4.0.0 — Dec 26, 2019

  • Support GHC-8.8, GHC-8.6, GHC-8.4, GHC-8.2. Drop older GHC versions support.
  • Update maintenance info.

0.3.1.0

  • Added ireplicateM and ireplicateM_.

0.3.0.0

  • ifind now returns the index alongside with the value (same as in lens).

0.2.0.0

  • izipWithM and izipWithM_ have been generalised from Monad to Applicative (which mimics what was done in base-4.9).

0.1.0.0

First release.