Fork me on GitHub
#clojure-uk
<
2020-12-16
>
dharrigan06:12:41

Good Morning!

djm08:12:13

👋 Thursday last week was my last day of work for the year - nice to have a relaxing finish to the year.

alexlynham10:12:02

FWIW i prefer routes defined as functions that take maps

alexlynham10:12:11

i like being able to execute them in the repl

alexlynham10:12:20

i like being able to unit test them like regular fns

dominicm10:12:17

Oh, you're all talking about handlers, not routers.

mccraigmccraig10:12:29

how does every route as a function work @jiriknesl? do they get called in sequence until one says yes ?

dharrigan20:12:05

Is it common, if you have a map and a value to a key is a function, to name the key something like foo-bar-fn?

dharrigan20:12:27

{:foo-bar-fn (fn [x y] (+ x y))} for example

dharrigan20:12:53

{:foo-bar (fn [x y] (+ x y))}

seancorfield20:12:54

@dharrigan I lean toward -fn (and you'll see that in next.jdbc and elsewhere in my OSS code) but I don't know how widespread that is...

mccraigmccraig07:12:37

i often use type-specific suffixes like -fn or -p for promises, -ch for channels, -s for streams...

mccraigmccraig08:12:44

i find it especially helpful in code where you have both wrapped and unwrapped versions of something floating around

dharrigan20:12:16

I think I agree, it makes it clearer what the key is about

jiriknesl22:12:24

@mccraigmccraig as @dharrigan says, your route is a triplet of name (keyword), url->action (fn), action->url (fn). Action route goes through all url->action which either return controller action with params or nothing. The last in a row is default catchall error router.

dominicm22:12:31

That sounds very slow :)

dominicm22:12:44

Also, how do you build your sitemap automatically!

jiriknesl22:12:28

It is not slower than Sinatra’s get '/' do … end or equivalent in almost all other frameworks out there.

jiriknesl22:12:59

For a sitemap, every router could potentially enumerate all routes the router is aware of.