These are chat archives for EntilZha/PyFunctional

20th
Sep 2015
Adrian Wielgosik
@adrian17
Sep 20 2015 11:42
This message was deleted
This message was deleted
This message was deleted
...what the heck?
In [19]: from fn import _

In [20]: _ > 0
Out[20]: (_ > 0)

In [21]: _ > 0
Out[21]: ((_ > 0) > 0)

In [22]: _ == 0
Out[22]: (((_ > 0) > 0) == 0)
Adrian Wielgosik
@adrian17
Sep 20 2015 13:43
...oh, yea, I forgot that's a thing in a shell
Adrian Wielgosik
@adrian17
Sep 20 2015 13:53
regarding seq.open(): I can't really use it as a generator as it's has a minimal scope
so currently seq.open("big.txt").take(10) is going to be much slower than seq(open("big.txt")).take(10) on a big file.
Adrian Wielgosik
@adrian17
Sep 20 2015 14:00
although I have no idea how to safely scope it too
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:13
Right, terminal session
does the reader interface have a return generator expression?
Adrian Wielgosik
@adrian17
Sep 20 2015 14:16
the file? you can do iter(file) which iterates over lines without loading the whole file. Alternatively, file.read(num_bytes) but that would require much more to handle manually.
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:16
I think the way to do it
hmm
file is itself an iterator
Adrian Wielgosik
@adrian17
Sep 20 2015 14:17
yup
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:18
So this goes back to the issue that seq usually expands the iterable thing
the tradoff being that a = seq(...)
then a.stuff
Adrian Wielgosik
@adrian17
Sep 20 2015 14:18
ah, true
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:18
called multiple times should return the same thing
I think
So I have thought that perhaps there should be an option to not force the iterator to expand
at the expense of not being able to call it multiple times
hmm, i wonder
Adrian Wielgosik
@adrian17
Sep 20 2015 14:20
you can't use file's generator multiple times, but if you seek(0) the file, it resets it
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:21
doing something like take(10) would be odd
Adrian Wielgosik
@adrian17
Sep 20 2015 14:21
why?
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:21
well, with generator it would return different things
er
maybe because of cache it wont
Adrian Wielgosik
@adrian17
Sep 20 2015 14:22
yup, cache could be used to store lines read so far. And that could be optional in case someone doesn't want to expand.
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:22
I think I know how to fix this, or at least make it better
I should return file, not expand teh file object in seq.open
Adrian Wielgosik
@adrian17
Sep 20 2015 14:22
Sure, that was just a performance suggestion
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:22
seq knows how to handle iterators
at least not force them to expand at the last second, I think that may in turn help with the take performance, but I'me not 100% sure
hmm, now the issue I have is that if I just return seq(open...)
the file is closed by the time I use it
since its in a with block
Adrian Wielgosik
@adrian17
Sep 20 2015 14:25
yup
That's the other issue I mentioned :/
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:25
might need some special handling
hmm
dont want to keep file open dangling, so maybe upon Lineage.evaluate I try to close it if it is a file
Adrian Wielgosik
@adrian17
Sep 20 2015 14:27
maybe don't open the file at all until it's evaluated?
It'd require reopening it on each reevaluation but it's probably a good tradeoff
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:29
I like that idea
not entirely sure how to implement
but I like it
perhaps return a custom iterator, which upon first call to next() opens the file
and when next() has nothing to return catch that, close the file, then reraise StopIterationor whatever the stop iteration exception is
Adrian Wielgosik
@adrian17
Sep 20 2015 14:39
also reopening the file would solve the iterator reusage problem
Pedro Rodriguez
@EntilZha
Sep 20 2015 14:41
right
Looks like a good solution, will work on it sometime today