Interface Fn1<A,B>
-
- Type Parameters:
A- The argument typeB- The result type
- All Superinterfaces:
Applicative<B,Fn1<A,?>>,Cartesian<A,B,Fn1<?,?>>,Cocartesian<A,B,Fn1<?,?>>,Contravariant<A,Profunctor<?,B,Fn1<?,?>>>,Functor<B,Fn1<A,?>>,Monad<B,Fn1<A,?>>,MonadReader<A,B,Fn1<A,?>>,MonadRec<B,Fn1<A,?>>,MonadWriter<A,B,Fn1<A,?>>,Profunctor<A,B,Fn1<?,?>>
- All Known Subinterfaces:
BiMonoidFactory<A,B,C>,BiPredicate<A,B>,BiSemigroupFactory<A,B,C>,Effect<A>,Fn0<A>,Fn2<A,B,C>,Fn3<A,B,C,D>,Fn4<A,B,C,D,E>,Fn5<A,B,C,D,E,F>,Fn6<A,B,C,D,E,F,G>,Fn7<A,B,C,D,E,F,G,H>,Fn8<A,B,C,D,E,F,G,H,I>,Kleisli<A,B,M,MB>,Monoid<A>,MonoidFactory<A,B>,Predicate<A>,Semigroup<A>,SemigroupFactory<A,B>
- All Known Implementing Classes:
$,Absent,AddAll,All,Alter,And,Any,AutoBracket,Between,Both,Bracket,CartesianProduct,CatMaybes,Clamp,CmpEq,CmpEqBy,CmpEqWith,Coalesce,Collapse,Collapse,Compare,Compose,Compose,Concat,Cons,Constantly,Cycle,Difference,Distinct,Downcast,Drop,DropWhile,Empty,Endo,EndoK,Eq,Filter,Find,First,Flatten,FoldLeft,FoldRight,Force,GroupBy,GT,GTBy,GTE,GTEBy,GTEWith,GTWith,Head,Id,IfThenElse,InGroupsOf,Init,Inits,Intersection,Intersperse,Into,Into1,Into3,Into4,Into5,Into6,Into7,Into8,Iterate,Join,Last,Last,LazyRec,LeftAll,LeftAll,LeftAny,LeftAny,LiftA2,LiftA3,LiftA4,LiftA5,LiftA6,LiftA7,LT,LTBy,LTE,LTEBy,LTEWith,LTWith,Magnetize,MagnetizeBy,Map,Matching,Max,MaxBy,MaxWith,Merge,Merge,MergeHMaps,MergeMaps,Min,MinBy,MinWith,Not,Occurrences,Or,Over,Partition,Peek,Peek2,Pre,PrependAll,Present,PutAll,RateLimit,Re,ReduceLeft,ReduceRight,Repeat,Replicate,Reverse,RightAll,RightAll,RightAny,RightAny,RunAll,RunAll,ScanLeft,Sequence,Set,Size,Slide,Snoc,Sort,SortBy,SortWith,Span,Tail,Tails,Take,TakeWhile,Times,ToArray,ToCollection,ToMap,Trampoline,Trivial,Tupler2,Uncons,Under,Unfoldr,Union,Until,Upcast,View,Xor,Zip,ZipWith
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Fn1<A,B> extends MonadRec<B,Fn1<A,?>>, MonadReader<A,B,Fn1<A,?>>, MonadWriter<A,B,Fn1<A,?>>, Cartesian<A,B,Fn1<?,?>>, Cocartesian<A,B,Fn1<?,?>>
A function taking a single argument. This is the core function type that all other function types extend and auto-curry with.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <C,D>
Fn2<A,C,D>andThen(Fn2<? super B,? super C,? extends D> after)Left-to-right composition between different arity functions.default Bapply(A a)Invoke this function explosively with the given argument.default Fn1<A,Tuple2<A,B>>carry()Pair the covariantly-positioned carrier type with the contravariantly-positioned carrier type.default <C> Fn1<Tuple2<C,A>,Tuple2<C,B>>cartesian()Pair a value with the input to this function, and preserve the paired value through to the output.default Fn1<A,B>censor(Fn1<? super A,? extends A> fn)Update the accumulated state.BcheckedApply(A a)Invoke this function with the given argument, potentially throwing anyThrowable.default Fn1<A,Choice2<A,B>>choose()Choose between a successful resultbor returning back the input,a.default <C> Fn1<Choice2<C,A>,Choice2<C,B>>cocartesian()Choose between either applying this function or returning back a different result altogether.default <Y,Z>
Fn2<Y,Z,B>compose(Fn2<? super Y,? super Z,? extends A> before)Right-to-left composition between different arity functions.default <Z> Fn1<Z,B>contraMap(Fn1<? super Z,? extends A> fn)Contravariantly mapA <- B.default <Z,C>
Fn1<Z,C>diMap(Fn1<? super Z,? extends A> lFn, Fn1<? super B,? extends C> rFn)Exercise bothdiMapLanddiMapRover this function in the same invocation.default <Z> Fn1<Z,B>diMapL(Fn1<? super Z,? extends A> fn)Contravariantly map over the argument to this function, producing a function that takes the new argument type, and produces the same result.default <C> Fn1<A,C>diMapR(Fn1<? super B,? extends C> fn)Covariantly map over the return value of this function, producing a function that takes the same argument, and produces the new result type.default <C> Fn1<A,C>discardL(Applicative<C,Fn1<A,?>> appB)Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.default <C> Fn1<A,B>discardR(Applicative<C,Fn1<A,?>> appB)Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.default <C> Fn1<A,C>flatMap(Fn1<? super B,? extends Monad<C,Fn1<A,?>>> f)Chain dependent computations that may continue or short-circuit based on previous results.default <C> Fn1<A,C>fmap(Fn1<? super B,? extends C> f)Left-to-right composition.static <A,B>
Fn1<A,B>fn1(Fn1<? super A,? extends B> fn)Static factory method for avoid explicit casting when using method references asFn1s.static <A,B>
Fn1<A,B>fromFunction(java.util.function.Function<? super A,? extends B> function)Static factory method for wrapping a javaFunctionin anFn1.default <C> Lazy<Fn1<A,C>>lazyZip(Lazy<? extends Applicative<Fn1<? super B,? extends C>,Fn1<A,?>>> lazyAppFn)Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.default <C> Fn1<A,Tuple2<B,C>>listens(Fn1<? super A,? extends C> fn)Map the accumulation into a value and pair it with the current output.default Fn1<A,B>local(Fn1<? super A,? extends A> fn)Modify thisMonadReader'senvironment after reading it but before running the effect.default <C> Fn1<A,C>pure(C c)Lift the valuebinto this applicative functor.static <A> Pure<Fn1<A,?>>pureFn1()default Fn1<A,B>self()default Fn0<B>thunk(A a)default java.util.function.Function<A,B>toFunction()Convert thisFn1to a javaFunction.default <C> Fn1<A,C>trampolineM(Fn1<? super B,? extends MonadRec<RecursiveResult<B,C>,Fn1<A,?>>> fn)Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.default <Z> Fn2<Z,A,B>widen()Widen this function's argument list by prepending an ignored argument of any type to the front.static <A,B>
Fn1<A,B>withSelf(Fn2<? super Fn1<? super A,? extends B>,? super A,? extends B> fn)Construct anFn1that has a reference to itself in scope at the time it is executed (presumably for recursive invocations).default <C> Fn1<A,C>zip(Fn2<A,B,C> appFn)default <C> Fn1<A,C>zip(Applicative<Fn1<? super B,? extends C>,Fn1<A,?>> appFn)Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
-
-
-
Method Detail
-
apply
default B apply(A a)
Invoke this function explosively with the given argument.- Parameters:
a- the argument- Returns:
- the result of the function application
-
checkedApply
B checkedApply(A a) throws java.lang.Throwable
Invoke this function with the given argument, potentially throwing anyThrowable.- Parameters:
a- the argument- Returns:
- the result of the function application
- Throws:
java.lang.Throwable- anything possibly thrown by the function
-
thunk
default Fn0<B> thunk(A a)
Convert thisFn1to anFn0by supplying an argument to this function. Useful for fixing an argument now, but deferring application until a later time.- Parameters:
a- the argument- Returns:
- an
Fn0
-
widen
default <Z> Fn2<Z,A,B> widen()
Widen this function's argument list by prepending an ignored argument of any type to the front.- Type Parameters:
Z- the new first argument type- Returns:
- the widened function
-
toFunction
default java.util.function.Function<A,B> toFunction()
Convert thisFn1to a javaFunction.- Returns:
- the
Function
-
local
default Fn1<A,B> local(Fn1<? super A,? extends A> fn)
Modify thisMonadReader'senvironment after reading it but before running the effect.- Specified by:
localin interfaceMonadReader<A,B,Fn1<A,?>>- Parameters:
fn- the modification function- Returns:
- the
MonadReaderwith a modified environment
-
listens
default <C> Fn1<A,Tuple2<B,C>> listens(Fn1<? super A,? extends C> fn)
Map the accumulation into a value and pair it with the current output.- Specified by:
listensin interfaceMonadWriter<A,B,Fn1<A,?>>- Type Parameters:
C- the mapped output- Parameters:
fn- the mapping function- Returns:
- the updated
MonadWriter
-
censor
default Fn1<A,B> censor(Fn1<? super A,? extends A> fn)
Update the accumulated state.- Specified by:
censorin interfaceMonadWriter<A,B,Fn1<A,?>>- Parameters:
fn- the update function- Returns:
- the updated
MonadWriter
-
flatMap
default <C> Fn1<A,C> flatMap(Fn1<? super B,? extends Monad<C,Fn1<A,?>>> f)
Chain dependent computations that may continue or short-circuit based on previous results.- Specified by:
flatMapin interfaceMonad<A,B>- Specified by:
flatMapin interfaceMonadReader<A,B,Fn1<A,?>>- Specified by:
flatMapin interfaceMonadRec<A,B>- Specified by:
flatMapin interfaceMonadWriter<A,B,Fn1<A,?>>- Type Parameters:
C- the resulting monad parameter type- Parameters:
f- the dependent computation over A- Returns:
- the new monad instance
-
fmap
default <C> Fn1<A,C> fmap(Fn1<? super B,? extends C> f)
Left-to-right composition.- Specified by:
fmapin interfaceApplicative<A,B>- Specified by:
fmapin interfaceFunctor<A,B>- Specified by:
fmapin interfaceMonad<A,B>- Specified by:
fmapin interfaceMonadReader<A,B,Fn1<A,?>>- Specified by:
fmapin interfaceMonadRec<A,B>- Specified by:
fmapin interfaceMonadWriter<A,B,Fn1<A,?>>- Type Parameters:
C- the return type of the next function to invoke- Parameters:
f- the function to invoke with this function's return value- Returns:
- a function representing the composition of this function and f
-
pure
default <C> Fn1<A,C> pure(C c)
Lift the valuebinto this applicative functor.- Specified by:
purein interfaceApplicative<A,B>- Specified by:
purein interfaceMonad<A,B>- Specified by:
purein interfaceMonadReader<A,B,Fn1<A,?>>- Specified by:
purein interfaceMonadRec<A,B>- Specified by:
purein interfaceMonadWriter<A,B,Fn1<A,?>>- Type Parameters:
C- the type of the returned applicative's parameter- Parameters:
c- the value- Returns:
- an instance of this applicative over b
-
zip
default <C> Fn1<A,C> zip(Applicative<Fn1<? super B,? extends C>,Fn1<A,?>> appFn)
Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.- Specified by:
zipin interfaceApplicative<A,B>- Specified by:
zipin interfaceMonad<A,B>- Specified by:
zipin interfaceMonadReader<A,B,Fn1<A,?>>- Specified by:
zipin interfaceMonadRec<A,B>- Specified by:
zipin interfaceMonadWriter<A,B,Fn1<A,?>>- Type Parameters:
C- the resulting applicative parameter type- Parameters:
appFn- the other applicative instance- Returns:
- the mapped applicative
-
lazyZip
default <C> Lazy<Fn1<A,C>> lazyZip(Lazy<? extends Applicative<Fn1<? super B,? extends C>,Fn1<A,?>>> lazyAppFn)
Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports. This is useful for applicatives that support lazy evaluation and early termination.- Specified by:
lazyZipin interfaceApplicative<A,B>- Specified by:
lazyZipin interfaceMonad<A,B>- Specified by:
lazyZipin interfaceMonadReader<A,B,Fn1<A,?>>- Specified by:
lazyZipin interfaceMonadRec<A,B>- Specified by:
lazyZipin interfaceMonadWriter<A,B,Fn1<A,?>>- Type Parameters:
C- the resulting applicative parameter type- Parameters:
lazyAppFn- the lazy other applicative instance- Returns:
- the mapped applicative
- See Also:
Maybe,Either
-
trampolineM
default <C> Fn1<A,C> trampolineM(Fn1<? super B,? extends MonadRec<RecursiveResult<B,C>,Fn1<A,?>>> fn)
Given some operation yielding aRecursiveResultinside thisMonadRec, internally trampoline the operation until it yields aterminationinstruction.Stack-safety depends on implementations guaranteeing that the growth of the call stack is a constant factor independent of the number of invocations of the operation. For various examples of how this can be achieved in stereotypical circumstances, see the referenced types.
- Specified by:
trampolineMin interfaceMonadRec<A,B>- Type Parameters:
C- the ultimate resulting carrier type- Parameters:
fn- the function to internally trampoline- Returns:
- the trampolined
MonadRec - See Also:
for a basic implementation,for a implementation,for an implementation leveraging an already stack-safe,for a implementation
-
discardL
default <C> Fn1<A,C> discardL(Applicative<C,Fn1<A,?>> appB)
Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB. This is generally useful for sequentially performing side-effects.- Specified by:
discardLin interfaceApplicative<A,B>- Specified by:
discardLin interfaceMonad<A,B>- Specified by:
discardLin interfaceMonadReader<A,B,Fn1<A,?>>- Specified by:
discardLin interfaceMonadRec<A,B>- Specified by:
discardLin interfaceMonadWriter<A,B,Fn1<A,?>>- Type Parameters:
C- the type of the returned Applicative's parameter- Parameters:
appB- the other Applicative- Returns:
- appB
-
discardR
default <C> Fn1<A,B> discardR(Applicative<C,Fn1<A,?>> appB)
Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative. This is generally useful for sequentially performing side-effects.- Specified by:
discardRin interfaceApplicative<A,B>- Specified by:
discardRin interfaceMonad<A,B>- Specified by:
discardRin interfaceMonadReader<A,B,Fn1<A,?>>- Specified by:
discardRin interfaceMonadRec<A,B>- Specified by:
discardRin interfaceMonadWriter<A,B,Fn1<A,?>>- Type Parameters:
C- the type of appB's parameter- Parameters:
appB- the other Applicative- Returns:
- this Applicative
-
diMapL
default <Z> Fn1<Z,B> diMapL(Fn1<? super Z,? extends A> fn)
Contravariantly map over the argument to this function, producing a function that takes the new argument type, and produces the same result.- Specified by:
diMapLin interfaceCartesian<A,B,Fn1<?,?>>- Specified by:
diMapLin interfaceCocartesian<A,B,Fn1<?,?>>- Specified by:
diMapLin interfaceProfunctor<A,B,Fn1<?,?>>- Type Parameters:
Z- the new argument type- Parameters:
fn- the contravariant argument mapping function- Returns:
- an
Fn1<Z, B>
-
diMapR
default <C> Fn1<A,C> diMapR(Fn1<? super B,? extends C> fn)
Covariantly map over the return value of this function, producing a function that takes the same argument, and produces the new result type.- Specified by:
diMapRin interfaceCartesian<A,B,Fn1<?,?>>- Specified by:
diMapRin interfaceCocartesian<A,B,Fn1<?,?>>- Specified by:
diMapRin interfaceProfunctor<A,B,Fn1<?,?>>- Type Parameters:
C- the new result type- Parameters:
fn- the covariant result mapping function- Returns:
- an
Fn1<A, C>
-
diMap
default <Z,C> Fn1<Z,C> diMap(Fn1<? super Z,? extends A> lFn, Fn1<? super B,? extends C> rFn)
Exercise bothdiMapLanddiMapRover this function in the same invocation.- Specified by:
diMapin interfaceCartesian<A,B,Fn1<?,?>>- Specified by:
diMapin interfaceCocartesian<A,B,Fn1<?,?>>- Specified by:
diMapin interfaceProfunctor<A,B,Fn1<?,?>>- Type Parameters:
Z- the new argument typeC- the new result type- Parameters:
lFn- the contravariant argument mapping functionrFn- the covariant result mapping function- Returns:
- an
Fn1<Z, C>
-
cartesian
default <C> Fn1<Tuple2<C,A>,Tuple2<C,B>> cartesian()
Pair a value with the input to this function, and preserve the paired value through to the output.
-
carry
default Fn1<A,Tuple2<A,B>> carry()
Pair the covariantly-positioned carrier type with the contravariantly-positioned carrier type. This can be thought of as "carrying" or "inspecting" the left parameter.
-
cocartesian
default <C> Fn1<Choice2<C,A>,Choice2<C,B>> cocartesian()
Choose between either applying this function or returning back a different result altogether.- Specified by:
cocartesianin interfaceCocartesian<A,B,Fn1<?,?>>- Type Parameters:
C- the potentially different result- Returns:
- teh strengthened
Fn1
-
choose
default Fn1<A,Choice2<A,B>> choose()
Choose between a successful resultbor returning back the input,a.
-
contraMap
default <Z> Fn1<Z,B> contraMap(Fn1<? super Z,? extends A> fn)
Contravariantly mapA <- B.- Specified by:
contraMapin interfaceCartesian<A,B,Fn1<?,?>>- Specified by:
contraMapin interfaceCocartesian<A,B,Fn1<?,?>>- Specified by:
contraMapin interfaceContravariant<A,B>- Specified by:
contraMapin interfaceProfunctor<A,B,Fn1<?,?>>- Type Parameters:
Z- the new parameter type- Parameters:
fn- the mapping function- Returns:
- the mapped Contravariant functor instance
-
compose
default <Y,Z> Fn2<Y,Z,B> compose(Fn2<? super Y,? super Z,? extends A> before)
Right-to-left composition between different arity functions. Preserves highest arity in the return type.- Type Parameters:
Y- the resulting function's first argument typeZ- the resulting function's second argument type- Parameters:
before- the function to pass its return value to this function's input- Returns:
- an
Fn2<Y, Z, B>
-
andThen
default <C,D> Fn2<A,C,D> andThen(Fn2<? super B,? super C,? extends D> after)
Left-to-right composition between different arity functions. Preserves highest arity in the return type.- Type Parameters:
C- the resulting function's second argument typeD- the resulting function's return type- Parameters:
after- the function to invoke on this function's return value- Returns:
- an
Fn2<A, C, D>
-
fn1
static <A,B> Fn1<A,B> fn1(Fn1<? super A,? extends B> fn)
Static factory method for avoid explicit casting when using method references asFn1s.- Type Parameters:
A- the input typeB- the output type- Parameters:
fn- the function to adapt- Returns:
- the
Fn1
-
fromFunction
static <A,B> Fn1<A,B> fromFunction(java.util.function.Function<? super A,? extends B> function)
Static factory method for wrapping a javaFunctionin anFn1.- Type Parameters:
A- the input typeB- the output type- Parameters:
function- the function- Returns:
- the
Fn1
-
pureFn1
static <A> Pure<Fn1<A,?>> pureFn1()
- Type Parameters:
A- the input type- Returns:
- the
Pureinstance
-
withSelf
static <A,B> Fn1<A,B> withSelf(Fn2<? super Fn1<? super A,? extends B>,? super A,? extends B> fn)
Construct anFn1that has a reference to itself in scope at the time it is executed (presumably for recursive invocations).- Type Parameters:
A- the input typeB- the output type- Parameters:
fn- the body of the function, with access to itself- Returns:
- the
Fn1
-
-