These are chat archives for ramda/ramda

27th
Jun 2018
Shawn Talbert
@ShawnTalbert
Jun 27 2018 04:14
I have an Iterator. Can I feed it to ramda happily or will will ramdajs barf if you don't feed it something basic like an array?
Simon Friis Vindum
@paldepind
Jun 27 2018 06:28
@ShawnTalbert Many Ramda functions accept iterables. But, as far as I know the docs don't always mention it.
Shawn Talbert
@ShawnTalbert
Jun 27 2018 12:39
Thanks @paldepind , I didn't know that. Unfortunately I'm in a strict ES5 target evironment so an Iterable isn't possible but an Iterator is. I've even tried a couple Symbol shims with no luck. After trying many related libraries I've discovered Immutable.js seems to handle Iterators well. Would it be a reasonable alternative to ramda?
Shawn Talbert
@ShawnTalbert
Jun 27 2018 13:34
is there documentation on which functions (if any) in ramda support iterators?
Simon Friis Vindum
@paldepind
Jun 27 2018 13:40
@ShawnTalbert Now I am slightly confused. Why are you interested in iterators if you're in an environment without iterables?
But, to answer your question: no functions in Ramda accepts iterators. The only way to use an iterator is to mutate them. Function using iterators will be impure so Ramda doesn't do that.
Iterators are imperative and impure. The spec is great when exposed through iterables but without iterables I don't see how iterators are useful in functional code?
Shawn Talbert
@ShawnTalbert
Jun 27 2018 13:43
"Iterable" implies the presence of Symbol.iterator which trivially exposes an Iterator. My environment doesn't have Symbol. An iterator may have to maintain internal state but I don't see why the output can't be treated as immutable.
Iterable is just a way to get an Iterator as far as I can tell. Nothing pure or functional about that.
Anyway, the very library with Immutable in its name supports them though their lazy Sequence. I'll just stick with that for now.
Simon Friis Vindum
@paldepind
Jun 27 2018 13:44
Yes, iterable is just a way to get an iterator. But to use an iterator you have to call next on it which mutates the iterator.
Shawn Talbert
@ShawnTalbert
Jun 27 2018 13:45
next doesn't necessarily mutate anything, it's just a generic way to get the next value.
If Iterable is just a way to get an Iterator then it's no more 'functional' than an Iterator alone, no?
Simon Friis Vindum
@paldepind
Jun 27 2018 13:50
next has to mutate. How else would it work?
Unless I'm mistaken the spec allows you to do things like myIterator.next(); myIterator.next(); const third = myIterator.next().value to get the third element. So next need to mutate the internal state of the iterator.
When one gets an Iterator by calling @@iterator one have ones own private iterator. So consuming it doesn't make the function impure.
I may be wrong though. But that is how I remember the spec.
Simon Friis Vindum
@paldepind
Jun 27 2018 14:13
I just looked at the spec. next returns an object with a done property and a value property. So the only way to iterate through an iterator is to repeatedly call next on the same iterator. Each next invocation returns something different so next cannot be pure. Additionally next will have to mutate the iterator. So a pure functions cannot do anything interesting with an iterator.
Shawn Talbert
@ShawnTalbert
Jun 27 2018 15:37
hmm, then ramda can't be interesting to streams in general?
Rocky Madden
@rockymadden
Jun 27 2018 16:07
You might check out most for that: https://github.com/cujojs/most
Or, more generally, FRP-based solutions.
https://github.com/funkia/hareactive too. Right, @paldepind? ;)
Brad Compton (he/him)
@Bradcomp
Jun 27 2018 16:14
Also, because Ramda does dispatching, it should work with user defined types (such as streams) that implement map, chain, etc. or their fantasy-land equivalents
Rocky Madden
@rockymadden
Jun 27 2018 16:15
Concerning most, fairly certain it works with iterators. I haven't used them myself, but it mentions supporting.
Shawn Talbert
@ShawnTalbert
Jun 27 2018 16:35
thanks guys
Simon Friis Vindum
@paldepind
Jun 27 2018 21:17
@rockymadden Most is definitely great! Hareative, well, we're still working on that :smile: