New ranges and algorithms

Philippe Sigaud philippe.sigaud at gmail.com
Mon Dec 21 15:19:12 PST 2009


Hello,

I posted to digitalmars.D a month ago to present some modules on ranges and algorithms but I didn't have a repository at the time. Here it is now:

http://www.dsource.org/projects/dranges/

Dranges is a small project to bring some new ranges and algorithms to D. Its main source of inspiration is

    * D2 std.range and std.algorithm
    * functions/actions on sequences found in other languages, like Haskell, Clojure, Python and Scala. 

Mainly, it's a way for me to understand ranges, algorithms on sequences and (a part of) the functional programming paradigm. It's really a 'learn as you go' project, so if you're interested in looking at the code, don't hesitate to tell me how it can be improved. I'm pretty sure it can!

As of this writing, dranges is divided into eight modules:

The first three are the main modules:
    * range2.d, which contains new higher order ranges (drop, dropWhile, takeWhile, knit...)
    * algorithm2.d, containing extensions on map/filter/reduce and some other algorithm like list comprehensions, unfold, iterate, etc.
    * phobos_extension.d, which proposes modification of std.range and std.algorithm functions: map (adding back/popBack/opIndex/length), filter (back/popBack) and some bug corrections to take and other functions (bugs declaration on puremagic will follow.) 

The five other modules are just there to help.
    * traits2.d,  some traits used by the first two modules (acting on type tuples)
    * functional2.d, also bringing some support for range2 and algorithm2: mainly transforming strings into n-ary functions (a generalization of unaryFun and binaryFun)
    * tuple2.d, functions on tuples (reversing, extracting, glueing, appending, etc.)
    * predicate.d, to bring together all predicates (boolean-returning functions)
    * tree.d a small module, just for me to understand how to iterate on binary trees.


  Philippe


More information about the Digitalmars-d-announce mailing list