Skip to content

Instantly share code, notes, and snippets.

@SimonRichardson
Last active December 22, 2015 06:18
Show Gist options
  • Select an option

  • Save SimonRichardson/6429554 to your computer and use it in GitHub Desktop.

Select an option

Save SimonRichardson/6429554 to your computer and use it in GitHub Desktop.
Building a router using partials.
var squishy = require('squishy-pants/bin/squishy-pants.min'),
log = squishy.IO(squishy.constant(
function(x) {
console.log(x);
}
)),
logger = squishy.curry(
function(prefix, value) {
log.ap(squishy.IO.of(prefix + ' > ' + value)).unsafePerform();
}
),
router = squishy.router().add(
function(a) {
return "/search/:query/:name";
},
function() {
return 'Hello World';
}
).add(
function(a) {
return "/ducky"
},
function(){
return 'Rubber Ducky';
}
),
result = squishy.fill(
10,
function(index) {
return router.route(squishy.isEven(index) ? '/ducky/' : '/search/hello/world');
}
);
logger('Output', result);
@SimonRichardson
Copy link
Copy Markdown
Author

This doesn't work atm, but shouldn't be hard to parse the predicate form.

@SimonRichardson
Copy link
Copy Markdown
Author

Even better I've implemented this via partial routing and therefore it's just built on constructs that already exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment