Share via


IScorable<Item,Score> Interface

Definition

Allow the scoring of items, with external comparison of scores, and enable the winner to take some action.

public interface IScorable<in Item,out Score>
type IScorable<'Item, 'Score> = interface
Public Interface IScorable(Of In Item, Out Score)

Type Parameters

Item
This type parameter is contravariant. That is, you can use either the type you specified or any type that is less derived. For more information about covariance and contravariance, see Covariance and Contravariance in Generics.
Score
This type parameter is covariant. That is, you can use either the type you specified or any type that is more derived. For more information about covariance and contravariance, see Covariance and Contravariance in Generics.
Derived

Remarks

We avoided the traditional "bool TryScore(Item item, object state, out Score score)" pattern to allow for Score generic type parameter covariance.

Methods

DoneAsync(Item, Object, CancellationToken)

The scoring process has completed - dispose of any scoped resources.

GetScore(Item, Object)

Gets the score for this item.

HasScore(Item, Object)

Returns whether this scorable wants to participate in scoring this item.

PostAsync(Item, Object, CancellationToken)

If this scorable wins, this method is called.

PrepareAsync(Item, CancellationToken)

Perform some asynchronous work to analyze the item and produce some opaque state.

Extension Methods

SelectItem<SourceItem,TargetItem,Score>(IScorable<TargetItem,Score>, Func<SourceItem,TargetItem>)

Project the item of a scorable using a lambda expression.

SelectScore<Item,SourceScore,TargetScore>(IScorable<Item,SourceScore>, Func<Item,SourceScore,TargetScore>)

Project the score of a scorable using a lambda expression.

TryPostAsync<Item,Score>(IScorable<Item,Score>, Item, CancellationToken)

Invoke the scorable calling protocol against a single scorable.

WhereScore<Item,Score>(IScorable<Item,Score>, Func<Item,Score,Boolean>)

Applies to