preferred

inline fun <Range, Option : Any, OptionId> PriorityList<Range>.preferred(offered: List<Option>, match: (Range, OptionId) -> Boolean, by: (Option) -> OptionId): Option?(source)

Selects the client's preferred option from a set of options offered by the server, matching a priority list against the id of the options.

Precondition: the Priority list is sorted in descending order of weight. This is guaranteed by the header parser and the function that creates a fixed PriorityList.

Parameters

offered

the list of options offered

match

a predicate that reports whether a range selects an option identified by its id

by

a function that returns an option's id


Selects the client's preferred option from a set of options offered by the server, when the range is a SimpleRange

This is useful for implementing content negotiation in the application, rather than in request routing.