highland
highland copied to clipboard
question, map() vs through()
Sorry. This is probably a very noob question but I don't see why there is a .map() function when .through() seems to do the same exact thing or more. Is there some underlying behavioral difference? When would you choose one over the other?
I don't think they do the same thing, they have different type signatures:
through :: (Stream a -> Stream b) -> Stream a -> Stream b
map :: (a -> b) -> Stream a -> Stream b
I'm not sure why you'd favour the first over the second if all you want to do was a simple map
.
hl([1,2,3]).through(xs => xs.map(x => x + 1)).each(console.log); // 2, 3, 4
hl([1,2,3]).map(x => x + 1).each(console.log); // 2, 3, 4