Package fj.function

Class Visitor


  • public final class Visitor
    extends java.lang.Object
    The essence of the visitor design pattern expressed polymorphically.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Visitor()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <A,​B>
      F<B,​F<A,​B>>
      association​(List<P2<A,​B>> x, Equal<A> eq)
      Uses an association list to perform a lookup with equality and returns a function that can be applied to a default, followed by the associated key to return a value.
      static <A,​B>
      F<P1<B>,​F<A,​B>>
      associationLazy​(List<P2<A,​B>> x, Equal<A> eq)
      Uses an association list to perform a lookup with equality and returns a function that can be applied to a default, followed by the associated key to return a value.
      static <X> X findFirst​(List<Option<X>> values, F0<X> def)
      Returns the first value available in the given list of optional values.
      static <X> X nullablefindFirst​(List<X> values, F0<X> def)
      Returns the first non-null value in the given list of optional values.
      static <A,​B>
      B
      nullableVisitor​(List<F<A,​B>> visitors, F0<B> def, A value)
      Returns the first non-null value found in the list of visitors after application of the given value, otherwise returns the given default.
      static <A,​B>
      B
      visitor​(List<F<A,​Option<B>>> visitors, F0<B> def, A value)
      Returns the first value found in the list of visitors after application of the given value, otherwise returns the given default.
      • Methods inherited from class java.lang.Object

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

      • Visitor

        private Visitor()
    • Method Detail

      • findFirst

        public static <X> X findFirst​(List<Option<X>> values,
                                      F0<X> def)
        Returns the first value available in the given list of optional values. If none is found return the given default value.
        Parameters:
        values - The optional values to search.
        def - The default value if no value is found in the list.
        Returns:
        The first value available in the given list of optional values. If none is found return the given default value.
      • nullablefindFirst

        public static <X> X nullablefindFirst​(List<X> values,
                                              F0<X> def)
        Returns the first non-null value in the given list of optional values. If none is found return the given default value.
        Parameters:
        values - The potentially null values to search.
        def - The default value if no value is found in the list.
        Returns:
        The first non-null value in the given list of optional values. If none is found return the given default value.
      • visitor

        public static <A,​B> B visitor​(List<F<A,​Option<B>>> visitors,
                                            F0<B> def,
                                            A value)
        Returns the first value found in the list of visitors after application of the given value, otherwise returns the given default.
        Parameters:
        visitors - The list of visitors to apply.
        def - The default if none of the visitors yield a value.
        value - The value to apply to the visitors.
        Returns:
        The first value found in the list of visitors after application of the given value, otherwise returns the given default.
      • nullableVisitor

        public static <A,​B> B nullableVisitor​(List<F<A,​B>> visitors,
                                                    F0<B> def,
                                                    A value)
        Returns the first non-null value found in the list of visitors after application of the given value, otherwise returns the given default.
        Parameters:
        visitors - The list of visitors to apply looking for a non-null.
        def - The default if none of the visitors yield a non-null value.
        value - The value to apply to the visitors.
        Returns:
        The first value found in the list of visitors after application of the given value, otherwise returns the given default.
      • association

        public static <A,​B> F<B,​F<A,​B>> association​(List<P2<A,​B>> x,
                                                                      Equal<A> eq)
        Uses an association list to perform a lookup with equality and returns a function that can be applied to a default, followed by the associated key to return a value.
        Parameters:
        x - The association list.
        eq - The equality for the association list keys.
        Returns:
        A function that can be applied to a default value (there is no association) and an associated key.
      • associationLazy

        public static <A,​B> F<P1<B>,​F<A,​B>> associationLazy​(List<P2<A,​B>> x,
                                                                              Equal<A> eq)
        Uses an association list to perform a lookup with equality and returns a function that can be applied to a default, followed by the associated key to return a value.
        Parameters:
        x - The association list.
        eq - The equality for the association list keys.
        Returns:
        A function that can be applied to a default value (there is no association) and an associated key.