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

  • Home
  • SEARCH
  • 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 7708355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:35:30+00:00 2026-06-01T00:35:30+00:00

I have a function foo that accepts a Boolean function def foo( f:(_)=>Boolean )

  • 0

I have a function foo that accepts a Boolean function

def foo( f:(_)=>Boolean ) = //do something with f

I can call foo as follows

foo( (x:Int) => x == 0 )

Now, I want modify foo to accept any function that returns Boolean. eg. the modified foo should work for the following cases.

foo( (x:Int, y:Int) => x == y)
foo( (x:Int, y:Int, z:Int) => x == y && y == z)
foo( (x:Double, y:Double, z:Double, p:Double) => x < y && y < z && z < p)
//and so on...

My first attempt was to modify foo as follows

def foo2( f:(_*)=>Boolean ) = //do something with f

But this does not work.

  • 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-01T00:35:31+00:00Added an answer on June 1, 2026 at 12:35 am

    What @Nicolas said.

    You can make the call site code slightly nicer using Function.tupled.

    scala> def foo[A](f: A => Boolean) = 0
    foo: [A](f: A => Boolean)Int
    
    scala> import Function.tupled
    import Function.tupled
    
    scala> foo(tupled((x: Int, y: Int) => x == y))
    res0: Int = 0
    
    scala> foo(tupled((x: Int, y: Int, z: Int) => x < y && y < z))
    res1: Int = 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a function foo that I want to call n times. In
I have a constexpr function that looks something like this: constexpr int foo(int bar)
I have a function that accepts a variable number of parameters: foo (Class... types);
I have a function foo() that in turn calls function bar(). How can I
I have some third-party Javascript that has statements like this: FOO = function() {
Let's say that I have an Erlang function, with spec. -spec foo(integer(), string()) ->
I have a function void foo() and inside foo I call the function void
I have a function that accepts a list of date objects and should output
I am trying to call a function that accepts an LPTSTR as a parameter.
I have some code that looks something like this: d = {'foo': True, 'bar':

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.