concept Apply in category .net

This is an excerpt from Manning's book Concurrency in .NET.
In practice, the function that takes more than one argument, in this case
ToThumbnail, is curried and lifted into theTasktype using theTask Pureextension method. Then, the resultingTask<Func<Image, Func<int, Image>>>is passed over the applicative functorApply, which injects its output,Task<Image>, into the next function applied overDownloadImageAsync.Ultimately, the last applicative functor operator
Applyhandles the transient parametermaxPixelselevated using thePureextension method. From the perspective of the functormapoperator, the curried functionToThumbnailCurriedis partially applied and is exercised against animageargument and then wrapped into the task. Therefore, conceptually, the signature is
Let’s analyze the functions
PureandApply. An applicative functor is a pattern implemented by two operations, defined here, whereAFrepresents any elevated type (in bold):Pure : T -> AF<R> Apply : AF<T -> R> -> AF<T> -> F<R>!@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":4}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":5}]]"} !@%STYLE%@!Intuitively, the
Pureoperator lifts a value into an elevated domain, and it’s equivalent to theReturnmonadic operator. The namePureis a convention for an applicative functor definition. But in the case of applicative functions, this operator elevates a function. TheApplyoperator is a two-parameter function, both part of the same elevated domain.
Figure 10.8 The
Applyoperator implements the function wrapped inside an elevated type to a value in the context. The process triggers the unwrapping of both values; then, because the first value is a function, it’s applied automatically to the second value. Finally, the output is wrapped back inside the context of the elevated type.![]()