Comments (4)
Ah. I realize I've misunderstood your original question. I'm glad you've found a solution. I can't really see a way to work around the problem of that trailing Future: You have to yield synchronously because Infinite only works with synchronous generators, and you only find out that the underlying async generator was done some ticks later, after having already yielded that Future.
from fluture.
Hi @ftaiolivista. I answered a very similar question some time ago. It was in a GitHub issue, so not that easy to discover. I converted it to a Q&A Discussion. I think it might be what you need: #478
from fluture.
Thank you @Avaq for the quick reply. Looked ad #478. Looks clear how to wrap a standard generator with Lazy List but not clear to me on how to wrap an async iterator that yield promises.
from fluture.
@Avaq got it working this way. The problem is that I have one last future with undefined value because the Infinite loop cancellation happen after one last promise with undefined value
import { S, F } from './src/lib.js' // S = sanctuary F = Fluture
import { createReadStream, promises as FS } from 'fs'
import parse from 'csv-parse'
import Infinite from 'lazy-infinite'
const parsing = createReadStream('file.csv').pipe(parse())
const infinite = asynciterable =>
Infinite.of(function * () {
const i = asynciterable[Symbol.asyncIterator]()
let goon = true
do {
yield F.attemptP(() =>
i.next().then(({ done, value }) => {
goon = !done
return done ? undefined : value
})
)
} while (goon)
})
S.pipe([
infinite,
F.map(
F.chain(v => {
console.log('process', v)
return F.after(2000)(v)
})
),
i => F.go(i.gen),
F.fork(err => console.error('err', err))(console.log)
])(parsing)
from fluture.
Related Issues (20)
- Error in readme HOT 4
- Can`t realize ap composition HOT 6
- Is it proven that Fluture Future is lawful? HOT 4
- Access computation value as return value HOT 3
- Why does encaseP / attemptP accepts only one parameter? HOT 4
- Event Streams handling HOT 5
- Any future for Fluture on React Native? HOT 4
- chainRej example doesn't include all code needed to replicate
- Consider preserving the specific Error sub-type when converting to Promise HOT 5
- Why not thenables? HOT 3
- Example Sanctuary integration code throws an error
- Unable to infer types in function passed to `map` HOT 13
- Investigate option for alternative debug api
- Make typings for algebras more strict
- It seams like `Hook (Future e a) b` is equivalent to `ContT a (Future e) b` HOT 1
- Add Future.assume?
- Using Fluture with Jest HOT 1
- TypeScript error using map HOT 4
- Use result of Future
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 fluture.