You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Something like this looks really verbose (and isn't really parallel), so assuming there is a better way?
varprocessedBags=[]vartransformFragile=compose(filter(x=>x.bagType=='fragile'),map(x=>merge(x,{luggageTag: 'Handle with care'})));vartransformHeavy=compose(filter(x=>x.bagType=='heavy'),map(x=>merge(x,{luggageTag: 'Watch your back!!'})));vartransformNormal=filter(x=>x.bagType=='normal')processedBags=into(processedBags,transformFragile,bags)processedBags=into(processedBags,transformHeavy,bags)processedBags=into(processedBags,transformNormal,bags)
Also attempted other variations w/a switch statement inside a mapper. Also doesn't feel right.
Thanks in advance.
The text was updated successfully, but these errors were encountered:
You'd probably want to do it with iterators. Fork spits out an object of key-iterator pairs - you can then keep working on them as needed and merge them back together. The bags use-case probably isn't a good one for forking (there's a better way to do it), but here's what forking would look like at least how I sometimes do it:
// Reusable fork and mergevarfork=filtersObj=>itemList=>seq(filtersObj,map(([key,filter])=>[key,toIter(itemList,filter)]));varmerge=forkedObj=>toArray(forkedObj,mapcat(kp=>kp[1]));vartransformFragile=compose(filter(x=>x.bagType==='fragile'),map(x=>Object.assign({},x,{luggageTag: 'Handle with care'})));vartransformHeavy=compose(filter(x=>x.bagType==='heavy'),map(x=>Object.assign({},x,{luggageTag: 'Watch your back!!'})));vartransformNormal=filter(x=>x.bagType==='normal')vartransform=compose(merge,fork({transformFragile, transformHeavy, transformNormal}));varprocessedBags=transform(bags);
Curious how forking and joining might be accomplished with this library?
..similar to this.
Something like this looks really verbose (and isn't really parallel), so assuming there is a better way?
Also attempted other variations w/a switch statement inside a mapper. Also doesn't feel right.
Thanks in advance.
The text was updated successfully, but these errors were encountered: