#could you not just do `is_hungry(

1 messages · Page 1 of 1 (latest)

vast mulch
#

I can't pass that around though

#

I want to be able to store that and run it later

ornate siren
vast mulch
#

I guess my ask isn't coming across clearly enough

vast mulch
#

@ornate siren here's what I was looking to make

using System;
using System.Collections.Generic;
using System.Linq;

public static class FuncUtils<X, Y> {
    public static Func<X, Y, bool> OR(IEnumerable<Func<X, Y, bool>> funcs) {
        return (x, y) => funcs.Any(f => f(x,y));
    }

    public static Func<X, Y, bool> AND(IEnumerable<Func<X, Y, bool>> funcs) {
        return (x, y) => funcs.All(f => f(x,y));
    }
}
#

I haven't tested it out yet, but this is hte idea

#

the only thing that this doesn't yet achieve for me is, I want the templatized type to be generic enough that it represents the set of all arguments, regardless of what the function parameter signature ends up looking like

ornate siren
vast mulch
#

Hmm, how does val represent multiple values? I don't understand that

manic vortex
#

You can use value tuple.

ornate siren
radiant spindle
#

A way compatible with C# design principles would be to have some kind of class container for your value with polymorphism.

vast mulch
#

Is strong typing not already violated with type templating?

#

I think the strategy of passing a tuple is fine, I'll just go with that

radiant spindle
#

Just to make it clear: generics are not the same as C++ templates. There are huge differences between the two.

vast mulch
#

oh interesting

#

I don't know anything about that

ornate siren
vast mulch
#

listen, getting this down will give me some super expressive code, so it's worth it

radiant spindle
#

Honestly, generics are usually a rabbit hole you don't want to go down. I usually try to avoid. Because halfway throw the implementation you discover a limitation that is not possible to overcome.