Every function that takes an Array should also allow an Iterable
So each one of these should also take an Iterable:
Helpers
- [ ]
mconcat - [ ]
mconcatMap - [ ]
mreduce - [ ]
mreduceMap - [ ]
take(new)
Pointfree
- [ ]
filter - [ ]
find(new) - [x]
head - [ ]
map - [ ]
reduce - [ ]
sequence - [ ]
tail - [ ]
traverse
Since we are now exposing the possibility of infinite values, makes sense to add a take function at this point.
how would this be implemented without changing the type or mutating the value? the value of using the known functions is that they take care of creating the correct type but i think filter/map/reduce won't work without mutation or changing type
I think though most of the others should be fine
hey @evilsoft I am wondering if you have some magical idea for this? cause i can't quite think of how to do many of these without returning an array instead of the original iterable?
I think we need to define a function that clone the object in a way that it doesn't loose the structure. We need some checks for base constructors like (Date, Array, String etc..) and clone it in the right way, and when its a normal object use something like Object.create and assign.
Something like (pretty basic without the base constructor checks)
let object = Object.create(Object.getPrototypeOf(source))
Object.assign(object, source)
let symbols = Object.getOwnPropertySymbols(source)
symbols.forEach(key => object[key] = source[key])
return object
To make it easier, we should clone only after isIterable(), so we could call it cloneIterable
@HenriqueLimas @evilsoft I think we may have made a mistake on this one when we did head. I am thinking that the behavior we started with in head is wrong. I'm thinking that it should be if a generator function is passed in, then we will invoke it and iterate, however if you pass in the result of a generator call then your expectation is that you want it iterated over.
What do you guys think?