Skip to content

leo60228/fennel-iter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Iter.fnl (0.2.0)

Tiny lazy iterator library for Fennel. This library defines an iterator as a function that takes a fixed argument and a state, and returns a new state and an element. This is a subset of what Fennel's each and Lua's for accept, and matches the return value of ipairs.

Table of contents

filter

Function signature:

(filter pred iter inv control)

Filter an iterator. For example, to only include even elements: (filter #(= (% x 2) 0) iter)

first

Function signature:

(first pred iter inv control)

Get the first element matching a predicate from an iterator. For example, to get the first element other than 2: (first #(not= $ 2) iter)

foldl

Function signature:

(foldl pred state iter inv control)

Applies a left fold to an iterator. For example, to sum an iterator: (foldl (fn [a x] (+ a x)) 0 iter)

head

Function signature:

(head iter inv control)

Get the first element from an iterator.

iterCollect

Function signature:

(iterCollect iter inv control)

Eagerly evaluates an iterator to convert it to a table.

map

Function signature:

(map pred iter inv startControl)

Map an iterator, skipping nil values. For example, to double each element: (map #(* $ 2) iter)


License: MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published