I have a message with 3 attributes: type, currency and amount.
I have a rule with 4 attributes, a destination, a message type, a currency and an amount.
I want to go through my rules and find a match to the message on the message type and return the destination, or null if there was no match
I'm using a vector for the fixed positions of the fields in the message and rule, I've defined them as follows:
user=> (def msg [100, "USD", 100])
#’user/msg
user=> (def rules [["FAL" 100 "UKP" 100] ["FBC" 101 "USD" 100]])
#’user/rules
Then I define some functions that extract the message type from a rule and a message:
user=>(defn rule-mt [[_ mt]] mt)
#’user/rule-mt
user=>(defn msg-mt [[mt]] mt)
#’user/msg-mt
I've defined a function to match the message types as follows:
user=>(defn match-mt [ msg rule ] ( = ( rule-mt rule ) ( msg-mt msg ) ) )
#’user/match-mt
So I can call this directly as follows to check if it matches the first rule:
user=>(match-mt msg (rules 0))
true
And then to see if it matches the second rule:
(match-mt msg (rules 1))
false
How do I iterate over my rules (vector of vectors) calling my match function and then return the destination field of a matching rule (the first field of the rule) ?