user983597
user983597

Reputation: 103

if then do in clojure

I have created 3 functions. Each connects to a database, runs a query and displays the result. Run indivually they all work fine. However I want the user to decide which report of 3+ to run, to do so they will select a parameter and hit an execute button. How do I write a nested if then do in Clojure to decide which functions to execute?

If param = "reporta" do execute functiona else if param = "reportb" do execute functionb else etc etc etc

I have searched online but can't really find a good example of what I am trying to do... Any advise much appreciated.

Upvotes: 4

Views: 416

Answers (2)

islon
islon

Reputation: 1207

You can use case for your problem:

(case param
  "reporta" (do-something-a)
  "reportb" (do-something-b)
  (else-case))

Upvotes: 3

Dave Ray
Dave Ray

Reputation: 40005

Use cond or condp:

(condp = param
  "reporta"    (functiona)
  "reportb"    (functionb)
  (function-else))   

Alternatively, you could use a map of functions and just index by param.

Upvotes: 11

Related Questions