Record Class Option.Some<T>
java.lang.Object
java.lang.Record
cloud.opencode.base.functional.monad.Option.Some<T>
- Type Parameters:
T- value type - 值类型
- All Implemented Interfaces:
Option<T>
Some - Contains a value
Some - 包含值
- Since:
- JDK 25, opencode-base-functional V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
-
Nested Class Summary
Nested classes/interfaces inherited from interface Option
Option.None<T>, Option.Some<T> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.Filter the value with predicate 使用谓词过滤值<U> Option<U> Transform to another Option if Some 如果是 Some 则转换为另一个 Option<R> RFold this Option by applying one of two functions 通过应用两个函数之一来折叠此 Optionget()Get the value, throws if None 获取值,如果是 None 则抛出异常Get value or compute default if None 获取值或计算默认值(如果是 None)Get value or default if None 获取值或默认值(如果是 None)final inthashCode()Returns a hash code value for this object.booleanisNone()Check if this is None 检查是否为 NonebooleanisSome()Check if this is Some 检查是否为 Some<U> Option<U> Transform the value if Some 如果是 Some 则转换值Execute action if None 如果是 None 则执行操作Return this or other Option if None 返回本 Option 或其他 Option(如果是 None)Return this or computed Option if None 返回本 Option 或计算的 Option(如果是 None)Execute action if Some 如果是 Some 则执行操作toEither(L left) Convert to Either (None becomes Left) 转换为 Either(None 变为 Left)Convert to Optional 转换为 OptionaltoString()Returns a string representation of this record class.value()Returns the value of thevaluerecord component.
-
Constructor Details
-
Some
Creates an instance of aSomerecord class.- Parameters:
value- the value for thevaluerecord component
-
-
Method Details
-
isSome
-
isNone
-
get
-
map
Description copied from interface:OptionTransform the value if Some 如果是 Some 则转换值 -
flatMap
Description copied from interface:OptionTransform to another Option if Some 如果是 Some 则转换为另一个 Option -
filter
-
fold
Description copied from interface:OptionFold this Option by applying one of two functions 通过应用两个函数之一来折叠此 OptionThis is the catamorphism for Option - handles both cases symmetrically.
这是 Option 的态射 - 对称地处理两种情况。
Example | 示例:
String result = option.fold( () -> "No value", // None case value -> "Got: " + value // Some case ); -
getOrElse
-
getOrElse
-
orElse
-
orElse
Description copied from interface:OptionReturn this or computed Option if None 返回本 Option 或计算的 Option(如果是 None) -
toOptional
-
toEither
Description copied from interface:OptionConvert to Either (None becomes Left) 转换为 Either(None 变为 Left) -
peek
-
onNone
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
value
Returns the value of thevaluerecord component.- Returns:
- the value of the
valuerecord component
-