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
Modifier and TypeMethodDescriptionLeft-to-right composition between different arity functions.default BInvoke this function explosively with the given argument.carry()Pair the covariantly-positioned carrier type with the contravariantly-positioned carrier type.Pair a value with the input to this function, and preserve the paired value through to the output.Update the accumulated state.checkedApply(A a) Invoke this function with the given argument, potentially throwing anyThrowable.choose()Choose between a successful resultbor returning back the input,a.Choose between either applying this function or returning back a different result altogether.Right-to-left composition between different arity functions.Contravariantly mapA <- B.default <Z,C> Fn1 <Z, C> Exercise bothdiMapLanddiMapRover this function in the same invocation.Contravariantly map over the argument to this function, producing a function that takes the new argument type, and produces the same result.Covariantly map over the return value of this function, producing a function that takes the same argument, and produces the new result type.discardL(Applicative<C, Fn1<A, ?>> appB) Sequence both thisApplicativeandappB, discarding thisApplicative'sresult and returningappB.discardR(Applicative<C, Fn1<A, ?>> appB) Sequence both thisApplicativeandappB, discardingappB'sresult and returning thisApplicative.Chain dependent computations that may continue or short-circuit based on previous results.Left-to-right composition.static <A,B> Fn1 <A, B> Static factory method for avoid explicit casting when using method references asFn1s.static <A,B> Fn1 <A, B> fromFunction(Function<? super A, ? extends B> function) Given alazyinstance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.Map the accumulation into a value and pair it with the current output.Modify thisMonadReader'senvironment after reading it but before running the effect.pure(C c) Lift the valuebinto this applicative functor.pureFn1()self()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.widen()Widen this function's argument list by prepending an ignored argument of any type to the front.static <A,B> Fn1 <A, B> Construct anFn1that has a reference to itself in scope at the time it is executed (presumably for recursive invocations).Given another instance of this applicative over a mapping function, "zip" the two instances together using whatever application semantics the current applicative supports.
-
Method Details
-
apply
Invoke this function explosively with the given argument.- Parameters:
a- the argument- Returns:
- the result of the function application
-
checkedApply
Invoke this function with the given argument, potentially throwing anyThrowable.- Parameters:
a- the argument- Returns:
- the result of the function application
- Throws:
Throwable- anything possibly thrown by the function
-
thunk
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
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
- Returns:
- the
Function
-
local
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
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
Update the accumulated state.- Specified by:
censorin interfaceMonadWriter<A,B, Fn1<A, ?>> - Parameters:
fn- the update function- Returns:
- the updated
MonadWriter
-
flatMap
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
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
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
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
-
zip
-
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:
-
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:
-
discardL
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
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
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
Covariantly map over the return value of this function, producing a function that takes the same argument, and produces the new result type. -
diMap
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
Pair a value with the input to this function, and preserve the paired value through to the output. -
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
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
Choose between a successful resultbor returning back the input,a. -
contraMap
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
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
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>
-
self
-
fn1
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
- Type Parameters:
A- the input typeB- the output type- Parameters:
function- the function- Returns:
- the
Fn1
-
pureFn1
- Type Parameters:
A- the input type- Returns:
- the
Pureinstance
-
withSelf
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
-