Comments (11)
I'm working on Zoom's idea presented in: zero-functional/zero-functional#74
the idea is to convert defined iterator to macros
iterator flatten[T](row: openArray[T]): T {.adapter.} =
block wrapper: ...
block before: ...
block after: ...
block reducer:
for it in row:
yield it
# generated code --------------------------------
# type checking stuff -
iterator flattenType[T](row: openArray[T]): T = discard
macro flattenReducer(row, accFnIdent): untyped =
result = quote:
for n in `row`:
yield n
const yieldPaths = @[
@[0, 4, 0],
]
result.replaceYieldsWrapperBody yieldPaths, accFnIdent
macro flattenBefore(): untyped = ... [same as flattenBody but in different context]
macro flattenAfter(): untyped = ...
template flattenWrapper(bodt): untyped = body
the pattern is gonna be:
def states
wrapper:
before
loop it:
reducer it
after
from iterrr.
I have thought about it for some time, IMO the performant and extensible solution doesn't exist.
For example, think of cycle
. How would you implement that with regular code? OK then how would you convert it to extensible pattern, in a way that pattern also works with take
or repeat
?
And if you could find that pattern, is it performent?
from iterrr.
Use nested loops mate. You have more control
from iterrr.
maybe there are some hopes
from iterrr.
the current implementation, detects the result type by tracking map
s.
implementing repeat
& cycle
is possible, but transformers like flatten
& zip
requires CORE re-implementation.
from iterrr.
well, I have an idea to implement this.
var s: seq[string] # let's assume that it has some value
s.items |> filter(it.len > 3) |> flatten().map[ch]($ch).filter(it != "0")
you can apply a transformer by |>
.
with different syntax (compared to filter
& map
), it's easy to track data transformation.
from iterrr.
actually I'm trying to figure out a way to easily extend iterrr
like mangle
.
see how easy it is with closure iterators!
https://github.com/baabelfish/mangle/blob/master/mangle.nim#L143-L149
from iterrr.
I didn't want to use a global variable to store custom adapters, the downside is you loose private/public access control, but there is no other choice [at least I can't think of it at the time - that's what
zero_functional
does too]
initial states - for now take a look at:
Lines 6 to 30 in 36962d8
and see how easy it is to define a custom adapter.
these examples actually work:
Lines 35 to 51 in 36962d8
result:
@[[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 2, 3], [4, 5, 6]]
@[1, 2, 3, 4, 5, 6, 7, 8, 9]
@[@[1, 2], @[3, 4], @[5, 6], @[7, 8], @[9, 1]]
@[1, 2, 3, 4, 5, 6, 7, 8, 9, 1]
@[@[[1, 2, 3], [4, 5, 6]]]
@[@[[1, 2, 3], [4, 5, 6]], @[[7, 8, 9]]]
from iterrr.
there are issues with adapters overloading. you can't overload a adapter with the same arity for sure, but there might be solution for overloading with different arity[number of arguments].
from iterrr.
Don't forget about group tails.
iterator group(loop: T; `every`, `wow`: int = 1): seq[T] {.adapter.} =
var `gacc` = newSeqOfCap[T](`every`)
for it in loop:
`gacc`.add it
if `gacc`.len == `every`:
yield `gacc`
`gacc`.setLen(0)
if `gacc`.len > 0:
yield `gacc`
from iterrr.
Don't forget about group tails.
thanks. I've added inComplete
paramter.
Lines 21 to 30 in 0d6577c
UPDATE
from iterrr.
Related Issues (20)
- Add inplace reducer
- Optimize `replacedIdent`
- add support for more syntax flexibility HOT 2
- Add non operator version
- Add `ifor`
- replace `><` with `|>`
- add another syntax for custom idents
- Add doc for adapters
- problem with nested calls HOT 1
- nested call variable shadowing HOT 3
- `acc` name collision
- make it simple, make it usable
- remove unncessary `untyped` from template args in generated code
- Replace `with` by `inject`
- add `define` HOT 1
- `iterrr` macro removed. HOT 8
- nested problems HOT 3
- add custom reducer
- Add `isum`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iterrr.