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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:43:14+00:00 2026-06-09T17:43:14+00:00

This is the code in question. Something of a description/explination is included below object

  • 0

This is the code in question. Something of a description/explination is included below

object Functions {
  import scala.reflect.Manifest
  private var functions: List[(Manifest[_],Any,String)] = List()
  def add[T](desc: String,func: T)(implicit m: Manifest[T]) {
    functions ::= (m,func,desc)
  }

  def get[T]()(implicit m : Manifest[T]): List[(T,String)] = {
    functions flatMap {
      case (t,f,s) => if (t <:< m) Some(f.asInstanceOf[T],s) else None
    }
  }

  def getInputs[T]()(implicit m : Manifest[T]): List[(T => Any,String)] = {
  functions flatMap {
    case (t,f,s) => if (t <:< (T => Any)) Some(f.asInstanceOf[T => Any],s) else None
    }
  }

Basically my goal is to have a list of functions, with their types (input and output) perserved and the ability to search for specific functions based off of what they take as input and what they take as output. I am starting to believe that this is not possible in scala without some sort of a monkey patch, which I would like to avoid.

  • 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-09T17:43:16+00:00Added an answer on June 9, 2026 at 5:43 pm

    You should be able to do what you want with shapeless‘s HLists,

    Sample REPL session,

    scala> import shapeless._
    import shapeless._
    
    scala> val f1 : String => Int = _.length
    f1: String => Int = <function1>
    
    scala> val f2 : Boolean => Boolean = !_
    f2: Boolean => Boolean = <function1>
    
    scala> val f3 : Int => String = "("+_+")"
    f3: Int => String = <function1>
    
    scala> val fs = f1 :: f2 :: f3 :: HNil
    fs: (String => Int) :: (Boolean => Boolean) :: (Int => String) :: HNil =
      <function1> :: <function1> :: <function1> :: HNil
    
    scala> val args = "foo" :: true :: 23 :: HNil
    args: String :: Boolean :: Int :: HNil = foo :: true :: 23 :: HNil
    
    scala> fs zipApply args
    res0: Int :: Boolean :: String :: HNil = 3 :: false :: (23) :: HNil
    

    Note that the individual types of the functions are preserved in the HList fs, that the individual types of the argument values are preserved in args, and that the types of the elements of the result of the zipApply are determined appropriately by the types of the corresponding function and argument.

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

Sidebar

Related Questions

In answering this code golf question , I ran across a problem in my
This isn't a code question for once, but it definitely has me confused. Basically,
This is a code review question more then anything. I have the following problem:
This is a follow up from my previous question I have this code basically
I was checking out this question which has this code - (NSArray *) percentagesRGBArray:(float[])
This is more of a licencing issue than a code question. I really like
Simple question, how make this code working ? public class T { public static
Stupid question, this code: <?php $variable = system(cat /home/maxor/test.txt); echo $variable; ?> with file
So I just have posted a question about this code (which was answered): $(document).ready(Main);
Please check this code out it compiles and runs absolutely fine.. The question is

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.