davezych / shience

A .NET port(ish) of Github's Scientist library. (https://github.com/github/scientist)
MIT License
9 stars 1 forks source link

Add ability to specify 2 type parameters #35

Closed davezych closed 8 years ago

davezych commented 8 years ago

In some cases the control and candidate methods may not return the same types. In our all-to-overused permissions example, let's pretend UserPermissions.CheckUser(currentUser) returns a bool, but User.Can(currentUser, Permission.Read) returns a more complex object. In that case, we would have to set up the candidate as

() => {
    var userCanRead = User.Can(currentUser, Permission.Read);
    return userCanRead.HasPermission;
}

(I realize this is a terrible example.) Although not a huge deal, it's more verbose than it needs to be. Users might also want to compare 2 different complex types which is difficult in the current setup.

I propose an interface similar to this:

public sealed class Experiment<TResult, KResult>

This allows the control and candidate to have different types if necessary. We can also overload New to allow only specifying a single parameter if both are the same:

public static Experiment<TResult, TResult> New<TResult>([NotNull]string name)
public static Experiment<TResult, KResult> New<TResult, KResult>([NotNull]string name)

In the case of specifying 2 different types the user will have to include a comparer, but I think the functionality outweighs that very slight negative.

MovGP0 commented 8 years ago

that seems to be a good idea.

MovGP0 commented 8 years ago

done