def- / nim-iterutils Goto Github PK
View Code? Open in Web Editor NEWFunctional operations for iterators and slices, similar to sequtils, in Nim
Functional operations for iterators and slices, similar to sequtils, in Nim
Congratulations!!!
The GitHub(notreally) team has awarded you with the needed website of the week. If you want to win a lot of FAME and rock EVERYWHERE you go, please follow these steps to claim your new and FREE documentation website:
babel install gh_nimrod_doc_pages
.$ cd path/to/your/git/checkout
$ git checkout --orphan gh-pages
$ git rm -rf .
$ gh_nimrod_doc_pages -b
gh_nimrod_doc_pages.ini
file to contain the following lines:["gh-pages"]
update_html=index.html
doc_dir=docs
branches="master"
$ gh_nimrod_doc_pages -c .
$ git add . && git commit -v
$ git push --set-upstream origin gh-pages
Enjoy your new FREE website for your project at http://def-.github.io/iterutils/!!!
Disclaimers:
> nim c iterutils.nim
Hint: system [Processing]
Hint: iterutils [Processing]
....
Hint: parseutils [Processing]
SIGSEGV: Illegal storage access. (Try to compile with -d:useSysAssert -d:useGcAssert for details.)
Got here from your informative blog http://hookrace.net/blog/nim-adventures/
Tried to compile but can't. Compiler is v0.10.2.
Does it make sense to add the take
method that returns the first n
items in an iterator? Here is a rough idea:
import iterutils
iterator take[T](i: Iterable[T], n: Natural): T =
let i = toIter(i)
var pos = 0
for x in i():
if pos < n:
yield x
inc pos
for x in (1..10).take(5): # Output: 1 2 3 4 5
stdout.write ($x & " ")
echo ""
for x in (1..4).take(5): # number to take is < total iterator members
# (should output the whole original iterator: 1 2 3 4)
stdout.write ($x & " ")
echo ""
for x in (1..10).take(0): # number to take is 0
# (should return an empty iterator)
stdout.write ($x & " ")
echo ""
discard """
for x in (1..10).take(-5): # number to take is negative
# (should fail to compile)
stdout.write ($x & " ")
echo ""
"""
Concat works for other iterators like in your tests, but does not work with walkDir, I don't understand why:
import os, iterutils
# works
for n in concat(toIter(1..4), toIter(20..23)):
echo n
# does not work
for f in concat(walkDir("."), walkDir(".")):
echo f
I don't understand the error either:
C:\p\try\iterwalkdir.nim(6, 31) Error: attempting to call routine: 'walkDir'
found 'os.walkDir(dir: string, relative: bool, checkDir: bool) [declared in C:\Users\me\.choosenim\toolchains\nim-1.4.6\lib\pure\os.nim(2076, 10)]' of kind 'iterator
Maybe you can help?
Do you really mean:
requires: "nimrod > 0.9.4"
?
#test.nim
import iterutils
from sequtils import toSeq
import sugar
proc test1()=
for i in filter(map(filter(2..10, proc(x: int): bool = x mod 2 == 0),
proc(x: int): int = x * 2), proc(x: int): bool = x mod 8 == 0):
echo i
var s = toSeq (2..10).filter(proc(x): bool = x mod 2 == 0).
map(proc(x): int = x * 2).filter(proc(x): bool = x mod 8 == 0)
echo s
var a = (2..10).filter(proc(x: int): bool = x mod 2 == 0)
var b = a.map((x: int) => x * 2)
for i in b.map((x: int) => x + 2):
echo i
test1()
gives:
test.nim(19, 17) Error: invalid indentation
fixing that gives other errors, and nothing prints
This example should be a test file in this repo so others can fix it (ideally something ran by nimble test iterutils
)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.