3 ms·
Seems like you could just do var process = items => items.filter(isOk).map(toOtherType).flatten()
by icebraining 11y ago
Seems like you could just do
var process = items => items.filter(isOk).map(toOtherType).flatten()
- deleted 11y ago[deleted]
- CrossEye 11y agoThe difference starts to show when you want to partially apply some values. // process1 :: (Item -> Bool) -> [Item] -> [OtherType] // process2 :: [Item] -> [OtherType] process1(isOk, items); //=> [otherType1, otherType2, ...] process2(items); //=> [otherType1, otherType2, ...] var processR1 = seq(filter, map(toOtherType), flatten); var processR2 = processR1(isOk); var processT1 = (isOk, items) => items.filter(isOk).map(toOtherType).flatten() var processT2 = items => processT1(isOk, items) That's why I'm wondering if there's some easier way to do this.
- icebraining 11y agoI believe you can use partial() from this post[1] to do something like this: var processT1 = (isOk, items) => items.filter(isOk).map(toOtherType).flatten(); var processT2 = partial(processT1, isOk); http://benalman.com/news/2012/09/partial-application-in-javascript/#partial-application-from-the-left http://benalman.com/news/2012/09/partial-application-in-java...