highland icon indicating copy to clipboard operation
highland copied to clipboard

question, map() vs through()

Open amit777 opened this issue 8 years ago • 1 comments

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?

amit777 avatar Sep 26 '16 07:09 amit777

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

svozza avatar Sep 26 '16 08:09 svozza