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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:05:54+00:00 2026-06-11T12:05:54+00:00

Basically if I have a slice or array of any arbitrary functions, how can

  • 0

Basically if I have a slice or array of any arbitrary functions, how can I select only the ones that return int, or select only the ones that take ints?

I figured that I would need to use the reflect package, but just reading the docs didn’t really help me figure out exactly how to do it.

  • 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-11T12:05:55+00:00Added an answer on June 11, 2026 at 12:05 pm

    This program prints the functions taking an int as parameter or returning an int :

    package main
    
    import (
        "fmt"
        "reflect"
    )
    
    func main() {
        funcs := make([]interface{}, 3, 3) // I use interface{} to allow any kind of func
        funcs[0] = func (a int) (int) { return a+1} // good
        funcs[1] = func (a string) (int) { return len(a)} // good
        funcs[2] = func (a string) (string) { return ":("} // bad
        for _, fi := range funcs {
            f := reflect.ValueOf(fi)
            functype := f.Type()
            good := false
            for i:=0; i<functype.NumIn(); i++ {
                if "int"==functype.In(i).String() {
                    good = true // yes, there is an int among inputs
                    break
                }
            }
            for i:=0; i<functype.NumOut(); i++ {
                if "int"==functype.Out(i).String() {
                    good = true // yes, there is an int among outputs
                    break
                }
            }
            if good {
                fmt.Println(f)
            }
        }
    }
    

    I think the code is self explanatory

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

Sidebar

Related Questions

I basically have 7 select statements that I need to have the results output
I have this code that somebody helped me with here, it basically converts select
I'm having this problem, where basically, I have a big array, that I break
Not quite sure if I asked correctly, but basically I have an array that
I basically have a program that filters records from one excel file to another
I'm writing an Android app that is basically a ListView populated with an array
I think its called a slice... basically I have a list of lists: [['fmt/10',
I have four numbers that can possible be the same, but or most likely
Basically I have a page that launched a fancybox iframe. In that iframe I
Hey guys. Basically I have a CSS triangle that I've created, and it sits

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.