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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:30:15+00:00 2026-06-09T11:30:15+00:00

I have [a] that can be converted to [b] . Each a is distinct,

  • 0

I have [a] that can be converted to [b]. Each a is distinct, but each b may not be. I want to filter my [a] on the condition that the filtered [a] contains no duplicates when converted to [b].

Can someone help me to achieve this?

Edit

To serve as assistance, I’ll provide an example.

as = [1..10]
conv = even
bs = map even as
-- bs = [False,True,False,True,False,True,False,True,False,True]
-- filter <cond> as -- [1,2]
  • 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-06-09T11:30:17+00:00Added an answer on June 9, 2026 at 11:30 am

    Assume that f is the function that converts from a to b. You can then proceed in three steps:

    1. You pair each element of your list with its image under f: map (id &&& f);
    2. You remove every pair of which the second element has already appeared in the now obtained list: nubBy (on (==) snd);
    3. You drop the second component of each pair: map fst.

    Hence:

    import Control.Arrow ((&&&))
    import Data.Function (on)
    import Data.List (nubBy)
    
    filterOn :: Eq b => (a -> b) -> [a] -> [a]
    filterOn f = map fst . nubBy ((==) `on` snd) . map (id &&& f)
    

    For example:

    > filterOn even [1 .. 10]
    [1,2]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C# you can not have indexed properties. That said, how do I convert
I have a Location that can have Events. I want to have an upcoming_events
I have a class Something that implements ISomething . How can I convert/cast from
i have a javascript method that takes a date: convert(new Date(02/20/2010); how can i
I have members that can be blocked and when the member is blocked I
So basically I have website that has names of cities that can be checked
The Dutch and German language do have words that can be combined to new
I have a subclass of UITableViewController. I have code that can add/remove a UISearchBar
I have a button that can have a focus css class associated with it
I have a filename that can have multiple dots in it and could end

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.