Skip to content

Instantly share code, notes, and snippets.

@chvonrohr
Created June 14, 2019 14:05
Show Gist options
  • Save chvonrohr/1dec7b5f49ddf649073c8fc0f129686a to your computer and use it in GitHub Desktop.
Save chvonrohr/1dec7b5f49ddf649073c8fc0f129686a to your computer and use it in GitHub Desktop.
if-else – functional programming
export const conditionally = <Props, Result>(options: {
if: (props: Props) => any;
then: (props: Props) => Result | Result;
else: (props: Props) => Result | Result;
}) => (props: Props) => {
return options.if(props) ? options.then(props) : options.else(props);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment