Skip to content

Add converge analog from ramda #54

Open
sp3ber opened this issue Sep 25, 2019 · 0 comments
Open

Add converge analog from ramda #54

sp3ber opened this issue Sep 25, 2019 · 0 comments

Comments

@sp3ber
Copy link

sp3ber commented Sep 25, 2019

In some cases i need converge function, f.e.
`
const extractOfferSuggestions = pathOr(["offerSuggestions"], []);
const extractWordSuggestions = pathOr(["wordSuggestions"], []);
const mapSuggestionsToOptions = (suggestions): SuggestOption[] => [];

// without converge
const transformSuggestionsToOptions = suggestions => {
const wordSuggestions = extractWordSuggestions(suggestions);
const offerSuggestions = extractOfferSuggestions(suggestions);
return mapSuggestionsToOptions({
offerSuggestions,
wordSuggestions
});
};

// with converge
const transformSuggestionsToOptions = converge(
([wordSuggestions, offerSuggestions]) =>
mapSuggestionsToOptions({ offerSuggestions, wordSuggestions }),
[extractWordSuggestions, extractOfferSuggestions]
);
// or with other mapSuggestionsToOptions signature (two params instead of one object param)
const transformSuggestionsToOptions = converge(
mapSuggestionsToOptions,
[extractWordSuggestions, extractOfferSuggestions]
);
`
Some points on this combinator https://jrsinclair.com/articles/2019/compose-js-functions-multiple-parameters/

I think, createSelector from 'reselect' has the same idea (but with memoization)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant