Skip to content

Instantly share code, notes, and snippets.

@horiuchie
Last active January 5, 2020 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save horiuchie/a3cda36c7ff68ebbf7f8bd2b76eedd46 to your computer and use it in GitHub Desktop.
Save horiuchie/a3cda36c7ff68ebbf7f8bd2b76eedd46 to your computer and use it in GitHub Desktop.
incomplete "pattern matching" in Javascript
import * as R from 'ramda';
const condition = R.unapply(R.toString);
const sameAs = condition;
function viewMode (orientation, layoutNo) {
switch (condition(orientation, layoutNo)) {
case sameAs('portrait', 2):
return 'video and description';
case sameAs('landscape', 1):
case sameAs('landscape', 2):
return 'video only';
default:
return 'video and description and messages';
}
}
viewMode('portrait', 1);
// => video and description and messages
viewMode('portrait', 2);
// => video and description
viewMode('landscape', 2);
// => video only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment