Hey. I've been working on a iterator library for 2 weeks.

I'm happy to announce you that made it to the stable point.

for quick introduction, you may used `std/sequtils`.
    
    
    (-3..5).toseq.filterIt(it > 0).mapIt(it * it).max()
    # gives you 25
    
    
    Run

did you noticed that I've converted a `Hslice` to a `seq` in order to operate 
on it? ( **first problem** )

**another problem** is that it creates intermediate `seq` s. to demonstrate 
steps for above code:
    
    
    @[-3, -2, -1, ..., 5]  # initial seq
    @[1, 2, 3, 4, 5]  # filtered seq
    @[1, 4, 9, 16, 25]  # mapped seq
    25  # max
    
    
    Run

in this example, the code created _2_ intermediate `seq` s. in this example 
it's not very important but imagine you have a big `seq`/`range`/ ... and that 
can be both time and resource consuming.

### Meet `iterrr`

with `iterrr` you can keep almost the same style, and have the benefits of 
imperative programming.
    
    
    (-3..5) >< ifilter(it > 0).imap(it * it).imax() #25
    
    
    Run

which is almost identical to:
    
    
    block:
      var acc = iseqInit[typeof(default(typeof(-3..5)) * 
default(typeof(-3..5)))]()
      
      block mainLoop:
        for it in (-3..5):
          if it > 0:
            block:
              let it = it * it
              if not imax(acc, it):
                break mainLoop
      
      imaxFinalizer acc
    
    
    Run

### Features

#### custom ident

you can have other names rather than `it`.
    
    
    (-3..5) >< ifilter[n](n > 0).imap[n](n * n).imax()
    
    "hello".pairs >< ifilter[indx, c](indx > 2).imap[_, c](ord c) # [108, 111]
    
    
    Run

#### inline reducer
    
    
    let summ = 1..10 >< ireduce[acc, n](0):
      acc += n
    
    # summ: 55
    
    
    Run

#### not using reducer
    
    
    1..10 >< imap(it + 1).ifilter(it > 5).do(num):
       echo num
    
    # echos 6,7,8,9,10,11 each one in new line
    
    
    Run

#### define custom reducer + ...

for more information, visit the project 
[repo](https://forum.nim-lang.org/postActivity.xml#repo)

Reply via email to