Class Option.None<T>

java.lang.Object
cloud.opencode.base.functional.monad.Option.None<T>
Type Parameters:
T - value type - 值类型
All Implemented Interfaces:
Option<T>
Enclosing interface:
Option<T>

public static final class Option.None<T> extends Object implements Option<T>
None - Represents absence of value None - 表示值缺失
Since:
JDK 25, opencode-base-functional V1.0.0
Author:
Leon Soo www.LeonSoo.com
  • Method Details

    • isSome

      public boolean isSome()
      Description copied from interface: Option
      Check if this is Some 检查是否为 Some
      Specified by:
      isSome in interface Option<T>
      Returns:
      true if Some - 如果是 Some 返回 true
    • isNone

      public boolean isNone()
      Description copied from interface: Option
      Check if this is None 检查是否为 None
      Specified by:
      isNone in interface Option<T>
      Returns:
      true if None - 如果是 None 返回 true
    • get

      public T get()
      Description copied from interface: Option
      Get the value, throws if None 获取值,如果是 None 则抛出异常
      Specified by:
      get in interface Option<T>
      Returns:
      the value - 值
    • map

      public <U> Option<U> map(Function<? super T, ? extends U> mapper)
      Description copied from interface: Option
      Transform the value if Some 如果是 Some 则转换值
      Specified by:
      map in interface Option<T>
      Type Parameters:
      U - result type - 结果类型
      Parameters:
      mapper - transformation function - 转换函数
      Returns:
      transformed Option
    • flatMap

      public <U> Option<U> flatMap(Function<? super T, Option<U>> mapper)
      Description copied from interface: Option
      Transform to another Option if Some 如果是 Some 则转换为另一个 Option
      Specified by:
      flatMap in interface Option<T>
      Type Parameters:
      U - result type - 结果类型
      Parameters:
      mapper - transformation function returning Option - 返回 Option 的转换函数
      Returns:
      resulting Option
    • filter

      public Option<T> filter(Predicate<? super T> predicate)
      Description copied from interface: Option
      Filter the value with predicate 使用谓词过滤值
      Specified by:
      filter in interface Option<T>
      Parameters:
      predicate - filter condition - 过滤条件
      Returns:
      filtered Option (None if predicate not satisfied)
    • fold

      public <R> R fold(Supplier<? extends R> ifNone, Function<? super T, ? extends R> ifSome)
      Description copied from interface: Option
      Fold this Option by applying one of two functions 通过应用两个函数之一来折叠此 Option

      This is the catamorphism for Option - handles both cases symmetrically.

      这是 Option 的态射 - 对称地处理两种情况。

      Example | 示例:

      String result = option.fold(
          () -> "No value",          // None case
          value -> "Got: " + value    // Some case
      );
      
      Specified by:
      fold in interface Option<T>
      Type Parameters:
      R - result type - 结果类型
      Parameters:
      ifNone - function for None case - None 情况的函数
      ifSome - function for Some case - Some 情况的函数
      Returns:
      result of applying the appropriate function
    • getOrElse

      public T getOrElse(T defaultValue)
      Description copied from interface: Option
      Get value or default if None 获取值或默认值(如果是 None)
      Specified by:
      getOrElse in interface Option<T>
      Parameters:
      defaultValue - default value - 默认值
      Returns:
      value or default
    • getOrElse

      public T getOrElse(Supplier<? extends T> supplier)
      Description copied from interface: Option
      Get value or compute default if None 获取值或计算默认值(如果是 None)
      Specified by:
      getOrElse in interface Option<T>
      Parameters:
      supplier - default value supplier - 默认值供应商
      Returns:
      value or computed default
    • orElse

      public Option<T> orElse(Option<T> other)
      Description copied from interface: Option
      Return this or other Option if None 返回本 Option 或其他 Option(如果是 None)
      Specified by:
      orElse in interface Option<T>
      Parameters:
      other - alternative Option - 备选 Option
      Returns:
      this if Some, other if None
    • orElse

      public Option<T> orElse(Supplier<Option<T>> supplier)
      Description copied from interface: Option
      Return this or computed Option if None 返回本 Option 或计算的 Option(如果是 None)
      Specified by:
      orElse in interface Option<T>
      Parameters:
      supplier - Option supplier - Option 供应商
      Returns:
      this if Some, computed if None
    • toOptional

      public Optional<T> toOptional()
      Description copied from interface: Option
      Convert to Optional 转换为 Optional
      Specified by:
      toOptional in interface Option<T>
      Returns:
      Optional
    • toEither

      public <L> Either<L,T> toEither(L left)
      Description copied from interface: Option
      Convert to Either (None becomes Left) 转换为 Either(None 变为 Left)
      Specified by:
      toEither in interface Option<T>
      Type Parameters:
      L - left type - 左类型
      Parameters:
      left - value for Left if None - None 时的 Left 值
      Returns:
      Either
    • peek

      public Option<T> peek(Consumer<? super T> action)
      Description copied from interface: Option
      Execute action if Some 如果是 Some 则执行操作
      Specified by:
      peek in interface Option<T>
      Parameters:
      action - action to execute - 要执行的操作
      Returns:
      this Option for chaining
    • onNone

      public Option<T> onNone(Runnable action)
      Description copied from interface: Option
      Execute action if None 如果是 None 则执行操作
      Specified by:
      onNone in interface Option<T>
      Parameters:
      action - action to execute - 要执行的操作
      Returns:
      this Option for chaining
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object