Giter Site home page Giter Site logo

brandonhamilton / ilist Goto Github PK

View Code? Open in Web Editor NEW
10.0 4.0 1.0 70 KB

ℹ️ Index-related functions for lists

Home Page: https://hackage.haskell.org/package/ilist

License: Mozilla Public License 2.0

Haskell 100.00%
list indexed haskell-library hacktoberfest

ilist's Introduction

ilist

GitHub CI 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.

ilist's People

Contributors

brandonhamilton avatar chshersh avatar kquick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

kquick

ilist's Issues

Add 'imapFrom' function and family

Sometimes user needs to start mapping not from zero but from one. With old zip solution you can just replace zip [0..] with zip [1..] but there's no simple way to do it with ilist package. Source code of imap function gives clear way how to implement this function. And imap can be defined in terms of imapFrom without loss of performance most likely.

Well, it seems like a lot of functions can have *from version. If this change is too radical than I can propose to add such function per issue request.

Please widen the base bound to to 4.17 or 4.18

related to #15

Hi! I'm currently using a library dependent on this package with GHC 9.4.5 (base-4.17.0.0). However, it failed to compile as ilist requires latest base to be < 4.14.

It would be great to have the base bound updated to 4.17 and even 4.18! (for GHC 9.6) :D

ilist doesn't build on openSUSE Tumbleweed

When using cabal2spec, the tool automatically generates the specfile that indeed works as desired. However, this library defines in its cabal file that only up and excluding 4.14 is working with this library. Since on openSUSE Tumbleweed we have 4.14.3, this package requires a patch that changes the maximum allowed version of base.

When I apply said patch the package builds successfully.

diff --git a/ilist.cabal b/ilist.cabal
index 242bd38..3ffc337 100644
--- a/ilist.cabal
+++ b/ilist.cabal
@@ -29,7 +29,7 @@ source-repository head
   location:            https://github.com/kowainik/ilist.git
 
 common common-options
-  build-depends:       base >= 4.10 && < 4.14
+  build-depends:       base >= 4.10 && < 4.15
 
   ghc-options:         -Wall
                        -Wincomplete-uni-patterns

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.