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 6892905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:35:33+00:00 2026-05-27T06:35:33+00:00

let standard = (0, 4.5M, 4L) let tuples = [| (A, -2, 1.0M, 2L);

  • 0
let standard = (0, 4.5M, 4L)
let tuples = [| ("A", -2, 1.0M, 2L); 
                ("B", -1, 2.0M, 3L); 
                ("C", 0, 3.0M, 4L); 
                ("D", 1, 4.0M, 5L); 
                ("E", 2, 5.0M, 6L) |]
let qualified = tuples
              |> Array.sortBy(fun (_, a, b, c) -> (a, -b, c))
              |> Array.filter(fun (_, a, b, c) -> (a, b, c) <= standard)
printfn "%A" qualified

I have an array of tuples, and a standard. I want to sort the tuples and pick up those tuples which meet the requirements.
For the tuples, I ignore the first element, and sort the second element and forth element in ordinary way, but also sort the third element in reverse order; and I have a standard tuple, for all the tuples with the second element is at least as big as the standard, and the third element is at most as big as the standard are qualified tuples.
In the above example, the qualified tuple is: = [| (“C”, 0, 3.0M, 4L) |]
The conditions are: the second element >= 0 and the third element <= 4.5M and forth element >= 4L
But my code did NOT work!
Let me know how to write a function can do this job!
Thanks and have a nice weekend.
John

  • 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-27T06:35:33+00:00Added an answer on May 27, 2026 at 6:35 am

    I don’t think there is any clever way to do what you need using the built in comparison that works on tuples. The main problem is that the comparison treats first element as the most significant, so it decides just using the first few elements (without even considering the rest of the values. Your conditions specify restrictions on all elements. So, the solution from Gustavo is probably the easiest way to go.

    However, there are some minor points – firstly, it may be a good idea to perform filtering before sorting, because then your sorting function will need to sort fewer elements:

     let qualified = 
       tuples 
       |> Array.sortBy (...) 
       |> Array.filter (...)
    

    If you wanted to represent the condition in some global value that is easy to change, then creating a tuple with 3 values that specify the required minumum/maximum is not enough, because you don’t say whether the value is minimum or maximum… However, you could use a tuple of functions that specify the conditions:

    let standard = ((fun _ -> true), (<=) 0, (>=) 4.5M, (<=) 4L) 
    

    This specifies that all values of first element are OK, values of the second element should be larger than zero ( (<=) 0 stands for a function that takes x and returns 0 <= x) etc. Then you can write:

    let conditionsHold (p1, p2, p3, p4) (v1, v2, v3, v4) = 
      p1 v1 && p2 v2 && p3 v3 && p4 v4
    
    let qualified = 
      tuples 
      |> Array.sortBy(fun (_, a, b, c) -> (a, -b, c)) 
      |> Array.filter (conditionsHold standard)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I expect a list of items from the standard input which
Let's say I want to read a line from a socket, using the standard
Like the Delicious submission bookmark-let, I'd like to have some standard JavaScript I can
Let's say you have a class called Customer, which contains the following fields: UserName
I have a few projects in RAD 8.0, let's say DAOProject, EJBProject, WebProject, standard
Let's say we have a standard MainActivity that extends Activity . It contains onCreate
I am stuck with following monad problem: Let's say I have a standard monad
I encountered some really strange behaviour in Apache. I have a standard let PHP
Let's say I have a standard Python string (such as one obtained from raw_input()
Let's say I have a 2D array: int[][] a = new int[4][3]; populated such

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.