Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6900257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:31:23+00:00 2026-05-27T07:31:23+00:00

I have a message with 3 attributes: type, currency and amount. I have a

  • 0

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) ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:31:24+00:00Added an answer on May 27, 2026 at 7:31 am

    Just do it! Here’s a solution that finds all the rules that match a message using a for and then returns the first of them using first. However because of laziness, only one succesful match needs to be computed.

    (defn dest-of-rule [rule] (first rule))
    (defn get-dest [msg]
       (first
          (for [r rules
                :when (match-mt msg r)]
             (dest-of-rule r))))
    

    Here’s an alternative solution that does the same using filter:

    (defn get-dest [msg]
       (dest-of-rule (first (filter #(match-mt msg %) rules))))
    

    The first + filter idiom is very common and that’s why there’s a name for it: find-first. It is available e.g. in the package seq-utils (see here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my homework, I have to design a class Message; among other attributes, it
I have a message that I want to fadeIn when a form is successfully
I have a web service , i add some extra class which have message
I have a message handler, which consumes from a JMS queue and that sends
I have 2 Message driven beans. 2 Activation Specs for these beans. I have
I have a message box with 3 buttons: Yes, No, Help: var result =
I have a Message table and a User table. Both are in separate databases.
In C++, a console application can have a message handler in its WinMain procedure,
I have a simple message box in a WPF application that is launched as
I have a status message box (div box) positioned at the bottom of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.