Stay organized with collections
Save and categorize content based on your preferences.
BinaryOperator
@FunctionalInterface interface BinaryOperator<T : Any!> : BiFunction<T, T, T>
Represents an operation upon two operands of the same type, producing a result of the same type as the operands. This is a specialization of BiFunction
for the case where the operands and the result are all of the same type.
This is a functional interface whose functional method is apply(java.lang.Object,java.lang.Object)
.
Summary
Public methods |
open static BinaryOperator<T>! |
Returns a BinaryOperator which returns the greater of two elements according to the specified Comparator .
|
open static BinaryOperator<T>! |
Returns a BinaryOperator which returns the lesser of two elements according to the specified Comparator .
|
Inherited functions |
From class BiFunction
BiFunction<T, U, V>! |
andThen(after: Function<in R, out V>!)
Returns a composed function that first applies this function to its input, and then applies the after function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function.
|
R |
apply(t: T, u: U)
Applies this function to the given arguments.
|
|
Public methods
maxBy
open static fun <T : Any!> maxBy(comparator: Comparator<in T>!): BinaryOperator<T>!
Returns a BinaryOperator
which returns the greater of two elements according to the specified Comparator
.
Parameters |
<T> |
the type of the input arguments of the comparator |
comparator |
Comparator<in T>!: a Comparator for comparing the two values |
Return |
BinaryOperator<T>! |
a BinaryOperator which returns the greater of its operands, according to the supplied Comparator |
Exceptions |
java.lang.NullPointerException |
if the argument is null |
minBy
open static fun <T : Any!> minBy(comparator: Comparator<in T>!): BinaryOperator<T>!
Returns a BinaryOperator
which returns the lesser of two elements according to the specified Comparator
.
Parameters |
<T> |
the type of the input arguments of the comparator |
comparator |
Comparator<in T>!: a Comparator for comparing the two values |
Return |
BinaryOperator<T>! |
a BinaryOperator which returns the lesser of its operands, according to the supplied Comparator |
Exceptions |
java.lang.NullPointerException |
if the argument is null |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# BinaryOperator\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nBinaryOperator\n==============\n\n```\n@FunctionalInterface interface BinaryOperator\u003cT : Any!\u003e : BiFunction\u003cT, T, T\u003e\n```\n\n|----------------------------------------|\n| [java.util.function.BinaryOperator](#) |\n\nRepresents an operation upon two operands of the same type, producing a result of the same type as the operands. This is a specialization of [BiFunction](/reference/kotlin/java/util/function/BiFunction) for the case where the operands and the result are all of the same type.\n\nThis is a [functional interface](/reference/kotlin/java/util/function/package-summary) whose functional method is [apply(java.lang.Object,java.lang.Object)](/reference/kotlin/java/util/function/BiFunction#apply(java.util.function.BiFunction.T,%20java.util.function.BiFunction.U)).\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open static [BinaryOperator](#)\\\u003cT\\\u003e! | [maxBy](#maxBy(java.util.Comparator))`(`comparator:` `[Comparator](../Comparator.html#)\u003cin` `T\u003e!`)` Returns a [BinaryOperator](#) which returns the greater of two elements according to the specified `Comparator`. |\n| open static [BinaryOperator](#)\\\u003cT\\\u003e! | [minBy](#minBy(java.util.Comparator))`(`comparator:` `[Comparator](../Comparator.html#)\u003cin` `T\u003e!`)` Returns a [BinaryOperator](#) which returns the lesser of two elements according to the specified `Comparator`. |\n\n| Inherited functions ||\n|---|---|\n| From class [BiFunction](/reference/kotlin/java/util/function/BiFunction) |-----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [BiFunction](/reference/kotlin/java/util/function/BiFunction)\u003cT,` `U,` `V\u003e! | [andThen](/reference/kotlin/java/util/function/BiFunction#andThen(java.util.function.Function))`(`after:` `[Function](/reference/kotlin/java/util/function/Function)\u003cin` `R,` `out` `V\u003e!`)` Returns a composed function that first applies this function to its input, and then applies the `after` function to the result. If evaluation of either function throws an exception, it is relayed to the caller of the composed function. \u003cbr /\u003e | | R | [apply](/reference/kotlin/java/util/function/BiFunction#apply(java.util.function.BiFunction.T,%20java.util.function.BiFunction.U))`(`t:` `T`, `u:` `U`)` Applies this function to the given arguments. \u003cbr /\u003e | ||\n\nPublic methods\n--------------\n\n### maxBy\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen static fun \u003cT : Any!\u003e maxBy(comparator: Comparator\u003cin T\u003e!): BinaryOperator\u003cT\u003e!\n```\n\nReturns a [BinaryOperator](#) which returns the greater of two elements according to the specified `Comparator`.\n\n| Parameters ||\n|--------------|-----------------------------------------------------------------------------------------|\n| `\u003cT\u003e` | the type of the input arguments of the comparator |\n| `comparator` | [Comparator](../Comparator.html#)\\\u003cin T\\\u003e!: a `Comparator` for comparing the two values |\n\n| Return ||\n|-------------------------|------------------------------------------------------------------------------------------------------|\n| [BinaryOperator](#)\u003cT\u003e! | a `BinaryOperator` which returns the greater of its operands, according to the supplied `Comparator` |\n\n| Exceptions ||\n|----------------------------------|-------------------------|\n| `java.lang.NullPointerException` | if the argument is null |\n\n### minBy\n\nAdded in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen static fun \u003cT : Any!\u003e minBy(comparator: Comparator\u003cin T\u003e!): BinaryOperator\u003cT\u003e!\n```\n\nReturns a [BinaryOperator](#) which returns the lesser of two elements according to the specified `Comparator`.\n\n| Parameters ||\n|--------------|-----------------------------------------------------------------------------------------|\n| `\u003cT\u003e` | the type of the input arguments of the comparator |\n| `comparator` | [Comparator](../Comparator.html#)\\\u003cin T\\\u003e!: a `Comparator` for comparing the two values |\n\n| Return ||\n|-------------------------|-----------------------------------------------------------------------------------------------------|\n| [BinaryOperator](#)\u003cT\u003e! | a `BinaryOperator` which returns the lesser of its operands, according to the supplied `Comparator` |\n\n| Exceptions ||\n|----------------------------------|-------------------------|\n| `java.lang.NullPointerException` | if the argument is null |"]]