Answer the question
In order to leave comments, you need to log in
Currying, or is it still a function with several parameters?
Currying, or is it still a function with several parameters? What do you usually choose when writing code and why? Explain clearly.
Answer the question
In order to leave comments, you need to log in
Currying is often used in functional programming, when vendor code or some module takes a function as an input parameter and passes its own arguments to it, which you can use, but at the same time want to pass your own:
const foo = myArg => (interfaceArg1, interfaceArg2) => {
// do something
};
vendor(foo(someValue));
const buildMediaByConditionFn = conditionFn => (...args) => props => conditionFn(props) && css(...args);
const mobile = buildMediaByConditionFn(props => props.device.isMobile);
const desktop = buildMediaByConditionFn(props => !props.device.isMobile);
const media = {
mobile,
desktop,
};
export default media;
const Element = styled.div`
${props => props.device.isMobile && css`
position: fixed;
`}
`;
const Element = styled.div`
${media.mobile`
position: fixed;
`}
`;
const square = width => height => height * width;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question