Class Either

  • All Implemented Interfaces:

    
    public class Either<A extends Object, B extends Object>
    
                        

    ABの片方だけを保持するクラスです。

    Since:

    0.5.0

    Author:

    Hiiragi Tsubasa

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public final class Either.Left

      Aだけを保持するEitherの実装クラスです。

      public final class Either.Right

      Bだけを保持するEitherの実装クラスです。

    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Boolean isLeft() このインスタンスがLeftであるか判定します。
      final Boolean isRight() このインスタンスがRightであるか判定します。
      final <C extends Any> C map(Function1<A, C> left, Function1<B, C> right) 保持している値を変換します。
      final <C extends Any> Either<A, C> mapRight(Function1<B, C> right) 保持している値を変換します。
      final <C extends Any> Either<C, B> mapLeft(Function1<A, C> left) 保持している値を変換します。
      final Either<B, A> swap() 保持している値を入れ替えます。
      final Pair<A, B> toPair() 保持している値をPairに展開します。
      final B getRight() 右側の値を取得します。
      final A getLeft() 左側の値を取得します。
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • isLeft

         final Boolean isLeft()

        このインスタンスがLeftであるか判定します。

        Returns:

        Leftの場合はtrue,それ以外の場合はfalse

      • isRight

         final Boolean isRight()

        このインスタンスがRightであるか判定します。

        Returns:

        Rightの場合はtrue,それ以外の場合はfalse

      • map

         final <C extends Any> C map(Function1<A, C> left, Function1<B, C> right)

        保持している値を変換します。

        Parameters:
        left - このインスタンスがLeftの場合の変換ブロック
        right - このインスタンスがRightの場合の変換ブロック
        Returns:

        変換された値

      • mapRight

         final <C extends Any> Either<A, C> mapRight(Function1<B, C> right)

        保持している値を変換します。

        Parameters:
        right - このインスタンスがRightの場合の変換ブロック
        Returns:

        変換されたEitherのインスタンス

      • mapLeft

         final <C extends Any> Either<C, B> mapLeft(Function1<A, C> left)

        保持している値を変換します。

        Parameters:
        left - このインスタンスがLeftの場合の変換ブロック
        Returns:

        変換されたEitherのインスタンス

      • swap

         final Either<B, A> swap()

        保持している値を入れ替えます。

        Returns:

        値が入れ替わったEitherのインスタンス

      • toPair

         final Pair<A, B> toPair()

        保持している値をPairに展開します。

        Returns:

        展開されたPairのインスタンス

      • getRight

         final B getRight()

        右側の値を取得します。

        Returns:

        このインスタンスがLeftの場合はnull

      • getLeft

         final A getLeft()

        左側の値を取得します。

        Returns:

        このインスタンスがRightの場合はnull