Kind
open class Kind<F, A>
Simulates a Higher-Kinded Type in Swift with 1 type argument.
This class simulates Higher-Kinded Type support in Swift. Kind<F, A>
is an alias for F<A>
, which is not syntactically valid in Swift.
Classes that want to have HKT support must extend this class. Type parameter F
is reserved for a witness to prevent circular references in the inheritance relationship. By convention, witnesses are named like the class they represent, with the prefix For
. As an example:
class ForOption {}
class Option<A>: Kind<ForOption, A> {}
-
Default initializer
Declaration
Swift
public init()
-
Provides a traversal based on the instance of
Traverse
for this type.Declaration
Swift
static var traversalK: Traversal<Kind<F, A>, A> { get }
-
Undocumented
Declaration
Swift
static func ana<B>(_ a: B, _ coalgebra: @escaping Coalgebra<A, B>) -> Kind<F, A>
-
Undocumented
Declaration
Swift
func projectT() -> Kind<A, Kind<F, A>>
-
Undocumented
Declaration
Swift
static func project() -> Coalgebra<A, Kind<F, A>>
-
Converts this computation into a Resource.
Declaration
Swift
var asResource: Resource<F, A> { get }
-
Suspends side effects in the provided registration function. The parameter function is injected with a side-effectful callback for signaling the result of an asynchronous process.
Declaration
Swift
static func asyncF(_ procf: @escaping ProcF<F, F.E, A>) -> Kind<F, A>
Parameters
procf
Asynchronous operation.
Return Value
A computation describing the asynchronous operation.
-
Switches the evaluation of a computation to a different
DispatchQueue
.Declaration
Swift
func continueOn(_ queue: DispatchQueue) -> Kind<F, A>
Parameters
queue
A Dispatch Queue.
Return Value
A computation that will run on the provided queue.
-
Suspends side effects in the provided registration function. The parameter function is injected with a side-effectful callback for signaling the result of an asynchronous process.
Declaration
Swift
static func async(_ fa: @escaping Proc<F.E, A>) -> Kind<F, A>
Parameters
proc
Asynchronous operation.
Return Value
A computation describing the asynchronous operation.
-
Provides a computation that evaluates the provided function on every run.
Declaration
Swift
static func `defer`( _ queue: DispatchQueue, _ f: @escaping () -> Kind<F, A>) -> Kind<F, A>
Parameters
queue
Dispatch queue which the computation must be sent to.
f
Function returning a value.
Return Value
A computation that defers the execution of the provided function.
-
Provides a computation that evaluates the provided function on every run.
Declaration
Swift
static func later( _ queue: DispatchQueue, _ f: @escaping () throws -> A) -> Kind<F, A>
Parameters
queue
Dispatch queue which the computation must be sent to.
f
Function returning a value.
Return Value
A computation that defers the execution of the provided function.
-
Provides a computation that evaluates the provided function on every run.
Declaration
Swift
static func delayOrRaise<A>( _ queue: DispatchQueue, _ f: @escaping () -> Either<F.E, A>) -> Kind<F, A>
Parameters
queue
Dispatch queue which the computation must be sent to.
f
A function that provides a value or an error.
Return Value
A computation that defers the execution of the provided value.
-
Provides an asynchronous computation that never finishes.
Declaration
Swift
static func never() -> Kind<F, A>
Return Value
An asynchronous computation that never finishes.
-
A way to safely acquire a resource and release in the face of errors and cancellations. It uses
ExitCase
to distinguish between different exit cases when releasing the acquired resource.Declaration
Swift
func bracketCase<B>( release: @escaping (A, ExitCase<F.E>) -> Kind<F, Void>, use: @escaping (A) throws -> Kind<F, B>) -> Kind<F, B>
Parameters
release
Function to release the acquired resource.
use
Function to use the acquired resource.
Return Value
Computation describing the result of using the resource.
-
A way to safely acquire a resource and release in the face of errors and cancellations. It uses
ExitCase
to distinguish between different exit cases when releasing the acquired resource.Declaration
Swift
func bracket<B>( release: @escaping (A) -> Kind<F, Void>, use: @escaping (A) throws -> Kind<F, B>) -> Kind<F, B>
Parameters
release
Function to release the acquired resource, ignoring the outcome of the release of the resource.
use
Function to use the acquired resource.
Return Value
Computation describing the result of using the resource.
-
Forces this resource to be uncancelable even when an interruption happens.
Declaration
Swift
func uncancelable() -> Kind<F, A>
Return Value
An uncancelable computation.
-
Executes the given finalizer when the source is finished, either in success, error or cancelation.
Declaration
Swift
func guarantee(_ finalizer: Kind<F, Void>) -> Kind<F, A>
Parameters
finalizer
Finalizer function to be invoked when the resource is released.
Return Value
A computation describing the resouce that will invoke the finalizer when it is released.
-
Executes the given finalizer when the source is finished, either in success, error or cancelation, alowing to differentiate between exit conditions.
Declaration
Swift
func guaranteeCase(_ finalizer: @escaping (ExitCase<F.E>) -> Kind<F, Void>) -> Kind<F, A>
Parameters
finalizer
Finalizer function to be invoked when the resource is released, distinguishing the exit case.
Return Value
A computation describing the resource that will invoke the finalizer when it is released.
-
Runs 2 computations in parallel and tuples their results.
Declaration
Swift
static func parZip<Z, B>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>) -> Kind<F, (Z, B)> where A == (Z, B)
Parameters
fa
1st computation.
fb
2nd computation.
Return Value
A computation that describes the parallel execution.
-
Runs 3 computations in parallel and tuples their results.
Declaration
Swift
static func parZip<Z, B, C>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>) -> Kind<F, (Z, B, C)> where A == (Z, B, C)
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
Return Value
A computation that describes the parallel execution.
-
Runs 4 computations in parallel and tuples their results.
Declaration
Swift
static func parZip<Z, B, C, D>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>) -> Kind<F, (Z, B, C, D)> where A == (Z, B, C, D)
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
Return Value
A computation that describes the parallel execution.
-
Runs 5 computations in parallel and tuples their results.
Declaration
Swift
static func parZip<Z, B, C, D, E>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>) -> Kind<F, (Z, B, C, D, E)> where A == (Z, B, C, D, E)
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
fe
5th computation.
Return Value
A computation that describes the parallel execution.
-
Runs 6 computations in parallel and tuples their results.
Declaration
Swift
static func parZip<Z, B, C, D, E, G>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ fg: Kind<F, G>) -> Kind<F, (Z, B, C, D, E, G)> where A == (Z, B, C, D, E, G)
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
fe
5th computation.
fg
6th computation.
Return Value
A computation that describes the parallel execution.
-
Runs 7 computations in parallel and tuples their results.
Declaration
Swift
static func parZip<Z, B, C, D, E, G, H>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ fg: Kind<F, G>, _ fh: Kind<F, H>) -> Kind<F, (Z, B, C, D, E, G, H)> where A == (Z, B, C, D, E, G, H)
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
fe
5th computation.
fg
6th computation.
fh
7th computation.
Return Value
A computation that describes the parallel execution.
-
Runs 8 computations in parallel and tuples their results.
Declaration
Swift
static func parZip<Z, B, C, D, E, G, H, I>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ fg: Kind<F, G>, _ fh: Kind<F, H>, _ fi: Kind<F, I>) -> Kind<F, (Z, B, C, D, E, G, H, I)> where A == (Z, B, C, D, E, G, H, I)
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
fe
5th computation.
fg
6th computation.
fh
7th computation.
fi
8th computation.
Return Value
A computation that describes the parallel execution.
-
Runs 9 computations in parallel and tuples their results.
Declaration
Swift
static func parZip<Z, B, C, D, E, G, H, I, J>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ fg: Kind<F, G>, _ fh: Kind<F, H>, _ fi: Kind<F, I>, _ fj: Kind<F, J>) -> Kind<F, (Z, B, C, D, E, G, H, I, J)> where A == (Z, B, C, D, E, G, H, I, J)
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
fe
5th computation.
fg
6th computation.
fh
7th computation.
fi
8th computation.
fj
9th computation.
Return Value
A computation that describes the parallel execution.
-
Runs 2 computations in parallel and returns the result of the first one finishing.
Declaration
Swift
static func race<B, C>( _ fb: Kind<F, B>, _ fc: Kind<F, C>) -> Kind<F, A> where A == Either<B, C>
Parameters
fb
1st computation
fc
2nd computation
Return Value
A computation with the result of the first computation that finished.
-
Runs 2 computations in parallel and combines their results using the provided function.
Declaration
Swift
static func parMap<B, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ f: @escaping (Z, B) -> A) -> Kind<F, A>
Parameters
fa
1st computation.
fb
2nd computation.
f
Combination function.
Return Value
A computation that describes the parallel execution.
-
Runs 3 computations in parallel and combines their results using the provided function.
Declaration
Swift
static func parMap<B, C, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ f: @escaping (Z, B, C) -> A) -> Kind<F, A>
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
f
Combination function.
Return Value
A computation that describes the parallel execution.
-
Runs 4 computations in parallel and combines their results using the provided function.
Declaration
Swift
static func parMap<B, C, D, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ f: @escaping (Z, B, C, D) -> A) -> Kind<F, A>
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
f
Combination function.
Return Value
A computation that describes the parallel execution.
-
Runs 5 computations in parallel and combines their results using the provided function.
Declaration
Swift
static func parMap<B, C, D, E, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ f: @escaping (Z, B, C, D, E) -> A) -> Kind<F, A>
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
fe
5th computation.
f
Combination function.
Return Value
A computation that describes the parallel execution.
-
Runs 6 computations in parallel and combines their results using the provided function.
Declaration
Swift
static func parMap<B, C, D, E, G, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ fg: Kind<F, G>, _ f: @escaping (Z, B, C, D, E, G) -> A) -> Kind<F, A>
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
fe
5th computation.
fg
6th computation.
f
Combination function.
Return Value
A computation that describes the parallel execution.
-
Runs 7 computations in parallel and combines their results using the provided function.
Declaration
Swift
static func parMap<B, C, D, E, G, H, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ fg: Kind<F, G>, _ fh: Kind<F, H>, _ f: @escaping (Z, B, C, D, E, G, H) -> A) -> Kind<F, A>
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
fe
5th computation.
fg
6th computation.
fh
7th computation.
f
Combination function.
Return Value
A computation that describes the parallel execution.
-
Runs 8 computations in parallel and combines their results using the provided function.
Declaration
Swift
static func parMap<B, C, D, E, G, H, I, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ fg: Kind<F, G>, _ fh: Kind<F, H>, _ fi: Kind<F, I>, _ f: @escaping (Z, B, C, D, E, G, H, I) -> A) -> Kind<F, A>
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
fe
5th computation.
fg
6th computation.
fh
7th computation.
fi
8th computation.
f
Combination function.
Return Value
A computation that describes the parallel execution.
-
Runs 9 computations in parallel and combines their results using the provided function.
Declaration
Swift
static func parMap<B, C, D, E, G, H, I, J, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ fg: Kind<F, G>, _ fh: Kind<F, H>, _ fi: Kind<F, I>, _ fj: Kind<F, J>, _ f: @escaping (Z, B, C, D, E, G, H, I, J) -> A) -> Kind<F, A>
Parameters
fa
1st computation.
fb
2nd computation.
fc
3rd computation.
fd
4th computation.
fe
5th computation.
fg
6th computation.
fh
7th computation.
fi
8th computation.
fj
9th computation.
f
Combination function.
Return Value
A computation that describes the parallel execution.
-
Evaluates a side-effectful computation, allowing its cancellation.
Declaration
Swift
func runAsyncCancellable(_ callback: @escaping (Either<F.E, A>) -> Kind<F, Void>) -> Kind<F, Disposable>
Parameters
callback
Callback to process the result of the evaluation.
Return Value
A computation describing the evaluation, providing a means to cancel it.
-
Maps each element of this structure to an effect, evaluates them in parallel and collects the results.
Declaration
Swift
func parTraverse<G: Concurrent, B>(_ f: @escaping (A) -> Kind<G, B>) -> Kind<G, Kind<F, B>>
Parameters
f
A function producing an effect.
Return Value
Results collected under the context of the effect provided by the function.
-
Evaluate each effect in this structure of values in parallel and collects the results.
Declaration
Swift
func parSequence<G: Concurrent, AA>() -> Kind<G, Kind<F, AA>> where A == Kind<G, AA>
Return Value
Results collected under the context of the effects.
-
A parallel traverse followed by flattening the inner result.
Declaration
Swift
func parFlatTraverse<G: Concurrent, B>(_ f: @escaping (A) -> Kind<G, Kind<F, B>>) -> Kind<G, Kind<F, B>>
Parameters
f
A transforming function yielding nested effects.
Return Value
Results collected and flattened under the context of the effects.
-
Evaluates a side-effectful computation.
Declaration
Swift
func runAsync(_ callback: @escaping (Either<F.E, A>) -> Kind<F, ()>) -> Kind<F, Void>
Parameters
callback
Callback to process the result of the computation.
Return Value
A computation describing the evaluation.
-
Provides a computation that evaluates the provided function on every run.
Declaration
Swift
static func `defer`(_ fa: @escaping () -> Kind<F, A>) -> Kind<F, A>
Parameters
fa
Function returning a computation to be deferred.
Return Value
A computation that defers the execution of the provided function.
-
Provides a computation that evaluates the provided function on every run.
Declaration
Swift
static func later(_ f: @escaping () throws -> A) -> Kind<F, A>
Return Value
A computation that defers the execution of the provided function.
-
Provides a computation that evaluates this computation on every run.
Declaration
Swift
func later() -> Kind<F, A>
Return Value
A computation that defers the execution of the provided value.
-
Provides a computation that evaluates the provided function on every run.
Declaration
Swift
static func laterOrRaise(_ f: @escaping () -> Either<F.E, A>) -> Kind<F, A>
Parameters
f
A function that provides a value or an error.
Return Value
A computation that defers the execution of the provided value.
-
Provides a lazy computation that returns void.
Declaration
Swift
static func lazy() -> Kind<F, Void>
Return Value
A deferred computation of the void value.
-
Unsafely runs a computation in a synchronous manner.
Throws
Error happened during the execution of the computation, of the error type of the underlyingMonadError
.Declaration
Swift
func runBlocking(on queue: DispatchQueue = .main) throws -> A
Parameters
queue
Dispatch queue used to run the computation. Defaults to the main queue.
Return Value
Result of running the computation.
-
Unsafely runs a computation in an asynchronous manner.
Declaration
Swift
func runNonBlocking( on queue: DispatchQueue = .main, _ callback: @escaping Callback<F.E, A> = { _ in })
Parameters
queue
Dispatch queue used to run the computation. Defaults to the main queue.
callback
Callback to report the result of the evaluation.
-
Lifts a value to the context type implementing this instance of
Applicative
.This is a convenience method to call
Applicative.pure
as a static method of this type.Declaration
Swift
static func pure(_ a: A) -> Kind<F, A>
Parameters
a
Value to be lifted.
Return Value
Provided value in the context type implementing this instance.
-
Sequential application.
This is a convenience method to call
Applicative.ap
as an instance method of this type.Declaration
Swift
func ap<AA, B>(_ fa: Kind<F, AA>) -> Kind<F, B> where A == (AA) -> B
Parameters
fa
A value in the context implementing this instance.
Return Value
A value in the context implementing this instance, resulting of the transformation of the contained original value with the contained function.
-
Sequentially compose with another computation, discarding the value produced by this computation.
Declaration
Swift
func zipRight<B>(_ fb: Kind<F, B>) -> Kind<F, B>
Parameters
fb
Another computation.
Return Value
Result of running the second computation after the first one.
-
Sequentially compose with another computation, discarding the value produced by the provided computation.
Declaration
Swift
func zipLeft<B>(_ fb: Kind<F, B>) -> Kind<F, A>
Parameters
fb
2nd computation.
Return Value
Result produced from this computation after both are computed.
-
Creates a tuple in the context implementing this instance from two values in the same context.
This is a convenience method to call
Applicative.product
as a static method of this type.Declaration
Swift
static func product<AA, B>( _ fa: Kind<F, AA>, _ fb: Kind<F, B>) -> Kind<F, (AA, B)> where A == (AA, B)
Parameters
fa
1st value for the tuple.
fb
2nd value for the tuple.
Return Value
A tuple of the provided values in the context implementing this instance.
-
Adds an element to the right of a tuple in the context implementing this instance.
This is a convenience method to call
Applicative.product
as a static method of this type.Declaration
Swift
static func product<AA, B, Z>( _ fa: Kind<F, (AA, B)>, _ fz: Kind<F, Z>) -> Kind<F, (AA, B, Z)> where A == (AA, B, Z)
Parameters
fa
A tuple of two elements in the context implementing this instance.
fz
A value in the context implementing this instance.
Return Value
A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.
-
Adds an element to the right of a tuple in the context implementing this instance.
This is a convenience method to call
Applicative.product
as a static method of this type.Declaration
Swift
static func product<AA, B, C, Z>( _ fa: Kind<F, (AA, B, C)>, _ fz: Kind<F, Z>) -> Kind<F, (AA, B, C, Z)> where A == (AA, B, C, Z)
Parameters
fa
A tuple of three elements in the context implementing this instance.
fz
A value in the context implementing this instance.
Return Value
A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.
-
Adds an element to the right of a tuple in the context implementing this instance.
This is a convenience method to call
Applicative.product
as a static method of this type.Declaration
Swift
static func product<AA, B, C, D, Z>( _ fa: Kind<F, (AA, B, C, D)>, _ fz: Kind<F, Z>) -> Kind<F, (AA, B, C, D, Z)> where A == (AA, B, C, D, Z)
Parameters
fa
A tuple of four elements in the context implementing this instance.
fz
A value in the context implementing this instance.
Return Value
A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.
-
Adds an element to the right of a tuple in the context implementing this instance.
This is a convenience method to call
Applicative.product
as a static method of this type.Declaration
Swift
static func product<AA, B, C, D, E, Z>( _ fa: Kind<F, (AA, B, C, D, E)>, _ fz: Kind<F, Z>) -> Kind<F, (AA, B, C, D, E, Z)> where A == (AA, B, C, D, E, Z)
Parameters
fa
A tuple of five elements in the context implementing this instance.
fz
A value in the context implementing this instance.
Return Value
A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.
-
Adds an element to the right of a tuple in the context implementing this instance.
This is a convenience method to call
Applicative.product
as a static method of this type.Declaration
Swift
static func product<AA, B, C, D, E, G, Z>( _ fa: Kind<F, (AA, B, C, D, E, G)>, _ fz: Kind<F, Z>) -> Kind<F, (AA, B, C, D, E, G, Z)> where A == (AA, B, C, D, E, G, Z)
Parameters
fa
A tuple of six elements in the context implementing this instance.
fz
A value in the context implementing this instance.
Return Value
A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.
-
Adds an element to the right of a tuple in the context implementing this instance.
This is a convenience method to call
Applicative.product
as a static method of this type.Declaration
Swift
static func product<AA, B, C, D, E, G, H, Z>( _ fa: Kind<F, (AA, B, C, D, E, G, H)>, _ fz: Kind<F, Z>) -> Kind<F, (AA, B, C, D, E, G, H, Z)> where A == (AA, B, C, D, E, G, H, Z)
Parameters
fa
A tuple of seven elements in the context implementing this instance.
fz
A value in the context implementing this instance.
Return Value
A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.
-
Adds an element to the right of a tuple in the context implementing this instance.
This is a convenience method to call
Applicative.product
as a static method of this type.Declaration
Swift
static func product<AA, B, C, D, E, G, H, I, Z>( _ fa: Kind<F, (AA, B, C, D, E, G, H, I)>, _ fz: Kind<F, Z>) -> Kind<F, (AA, B, C, D, E, G, H, I, Z)> where A == (AA, B, C, D, E, G, H, I, Z)
Parameters
fa
A tuple of eight elements in the context implementing this instance.
fz
A value in the context implementing this instance.
Return Value
A tuple with the value of the second argument added to the right of the tuple, in the context implementing this instance.
-
Creates a tuple out of two values in the context implementing this instance.
This is a convenience method to call
Applicative.zip
as a static method of this type.Declaration
Swift
static func zip<AA, B>( _ a: Kind<F, AA>, _ b: Kind<F, B>) -> Kind<F, (AA, B)> where A == (AA, B)
Parameters
a
1st value of the tuple.
b
2nd value of the tuple.
Return Value
A tuple in the context implementing this instance.
-
Creates a tuple out of three values in the context implementing this instance.
This is a convenience method to call
Applicative.zip
as a static method of this type.Declaration
Swift
static func zip<AA, B, C>( _ a: Kind<F, AA>, _ b: Kind<F, B>, _ c: Kind<F, C>) -> Kind<F, (AA, B, C)> where A == (AA, B, C)
Parameters
a
1st value of the tuple.
b
2nd value of the tuple.
c
3rd value of the tuple.
Return Value
A tuple in the context implementing this instance.
-
Creates a tuple out of four values in the context implementing this instance.
This is a convenience method to call
Applicative.zip
as a static method of this type.Declaration
Swift
static func zip<AA, B, C, D>( _ a: Kind<F, AA>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>) -> Kind<F, (AA, B, C, D)> where A == (AA, B, C, D)
Parameters
a
1st value of the tuple.
b
2nd value of the tuple.
c
3rd value of the tuple.
d
4th value of the tuple.
Return Value
A tuple in the context implementing this instance.
-
Creates a tuple out of five values in the context implementing this instance.
This is a convenience method to call
Applicative.zip
as a static method of this type.Declaration
Swift
static func zip<AA, B, C, D, E>( _ a: Kind<F, AA>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ e: Kind<F, E>) -> Kind<F, (AA, B, C, D, E)> where A == (AA, B, C, D, E)
Parameters
a
1st value of the tuple.
b
2nd value of the tuple.
c
3rd value of the tuple.
d
4th value of the tuple.
e
5th value of the tuple.
Return Value
A tuple in the context implementing this instance.
-
Creates a tuple out of six values in the context implementing this instance.
This is a convenience method to call
Applicative.zip
as a static method of this type.Declaration
Swift
static func zip<AA, B, C, D, E, G>( _ a: Kind<F, AA>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ e: Kind<F, E>, _ g: Kind<F, G>) -> Kind<F, (AA, B, C, D, E, G)> where A == (AA, B, C, D, E, G)
Parameters
a
1st value of the tuple.
b
2nd value of the tuple.
c
3rd value of the tuple.
d
4th value of the tuple.
e
5th value of the tuple.
g
6th value of the tuple.
Return Value
A tuple in the context implementing this instance.
-
Creates a tuple out of seven values in the context implementing this instance.
This is a convenience method to call
Applicative.zip
as a static method of this type.Declaration
Swift
static func zip<AA, B, C, D, E, G, H>( _ a: Kind<F, AA>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ e: Kind<F, E>, _ g: Kind<F, G>, _ h: Kind<F, H>) -> Kind<F, (AA, B, C, D, E, G, H)> where A == (AA, B, C, D, E, G, H)
Parameters
a
1st value of the tuple.
b
2nd value of the tuple.
c
3rd value of the tuple.
d
4th value of the tuple.
e
5th value of the tuple.
g
6th value of the tuple.
h
7th value of the tuple.
Return Value
A tuple in the context implementing this instance.
-
Creates a tuple out of eight values in the context implementing this instance.
This is a convenience method to call
Applicative.zip
as a static method of this type.Declaration
Swift
static func zip<AA, B, C, D, E, G, H, I>( _ a: Kind<F, AA>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ e: Kind<F, E>, _ g: Kind<F, G>, _ h: Kind<F, H>, _ i: Kind<F, I>) -> Kind<F, (AA, B, C, D, E, G, H, I)> where A == (AA, B, C, D, E, G, H, I)
Parameters
a
1st value of the tuple.
b
2nd value of the tuple.
c
3rd value of the tuple.
d
4th value of the tuple.
e
5th value of the tuple.
g
6th value of the tuple.
h
7th value of the tuple.
i
8th value of the tuple.
Return Value
A tuple in the context implementing this instance.
-
Creates a tuple out of nine values in the context implementing this instance.
This is a convenience method to call
Applicative.zip
as a static method of this type.Declaration
Swift
static func zip<AA, B, C, D, E, G, H, I, J>( _ a: Kind<F, AA>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ e: Kind<F, E>, _ g: Kind<F, G>, _ h: Kind<F, H>, _ i: Kind<F, I>, _ j: Kind<F, J>) -> Kind<F, (AA, B, C, D, E, G, H, I, J)> where A == (AA, B, C, D, E, G, H, I, J)
Parameters
a
1st value of the tuple.
b
2nd value of the tuple.
c
3rd value of the tuple.
d
4th value of the tuple.
e
5th value of the tuple.
g
6th value of the tuple.
h
7th value of the tuple.
i
8th value of the tuple.
j
9th value of the tuple.
Return Value
A tuple in the context implementing this instance.
-
Combines the result of two computations in the context implementing this instance, using the provided function.
This is a convenience method to call
Applicative.map
as a static method of this type.Declaration
Swift
static func map<B, Z>( _ a: Kind<F, Z>, _ b: Kind<F, B>, _ f: @escaping (Z, B) -> A) -> Kind<F, A>
Parameters
a
1st computation.
b
2nd computation.
f
Combination function.
Return Value
Result of combining the provided computations, in the context implementing this instance.
-
Combines the result of three computations in the context implementing this instance, using the provided function.
This is a convenience method to call
Applicative.map
as a static method of this type.Declaration
Swift
static func map<B, C, Z>( _ a: Kind<F, Z>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ f: @escaping (Z, B, C) -> A) -> Kind<F, A>
Parameters
a
1st computation.
b
2nd computation.
c
3rd computation.
f
Combination function.
Return Value
Result of combining the provided computations, in the context implementing this instance.
-
Combines the result of four computations in the context implementing this instance, using the provided function.
This is a convenience method to call
Applicative.map
as a static method of this type.Declaration
Swift
static func map<B, C, D, Z>( _ a: Kind<F, Z>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ f: @escaping (Z, B, C, D) -> A) -> Kind<F, A>
Parameters
a
1st computation.
b
2nd computation.
c
3rd computation.
d
4th computation.
f
Combination function.
Return Value
Result of combining the provided computations, in the context implementing this instance.
-
Combines the result of five computations in the context implementing this instance, using the provided function.
This is a convenience method to call
Applicative.map
as a static method of this type.Declaration
Swift
static func map<B, C, D, E, Z>( _ a: Kind<F, Z>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ e: Kind<F, E>, _ f: @escaping (Z, B, C, D, E) -> A) -> Kind<F, A>
Parameters
a
1st computation.
b
2nd computation.
c
3rd computation.
d
4th computation.
e
5th computation.
f
Combination function.
Return Value
Result of combining the provided computations, in the context implementing this instance.
-
Combines the result of six computations in the context implementing this instance, using the provided function.
This is a convenience method to call
Applicative.map
as a static method of this type.Declaration
Swift
static func map<B, C, D, E, G, Z>( _ a: Kind<F, Z>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ e: Kind<F, E>, _ g: Kind<F, G>, _ f: @escaping (Z, B, C, D, E, G) -> A) -> Kind<F, A>
Parameters
a
1st computation.
b
2nd computation.
c
3rd computation.
d
4th computation.
e
5th computation.
g
6th computation.
f
Combination function.
Return Value
Result of combining the provided computations, in the context implementing this instance.
-
Combines the result of seven computations in the context implementing this instance, using the provided function.
This is a convenience method to call
Applicative.map
as a static method of this type.Declaration
Swift
static func map<B, C, D, E, G, H, Z>( _ a: Kind<F, Z>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ e: Kind<F, E>, _ g: Kind<F, G>, _ h: Kind<F, H>, _ f: @escaping (Z, B, C, D, E, G, H) -> A) -> Kind<F, A>
Parameters
a
1st computation.
b
2nd computation.
c
3rd computation.
d
4th computation.
e
5th computation.
g
6th computation.
h
7th computation.
f
Combination function.
Return Value
Result of combining the provided computations, in the context implementing this instance.
-
Combines the result of eight computations in the context implementing this instance, using the provided function.
This is a convenience method to call
Applicative.map
as a static method of this type.Declaration
Swift
static func map<B, C, D, E, G, H, I, Z>( _ a: Kind<F, Z>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ e: Kind<F, E>, _ g: Kind<F, G>, _ h: Kind<F, H>, _ i: Kind<F, I>, _ f: @escaping (Z, B, C, D, E, G, H, I) -> A) -> Kind<F, A>
Parameters
a
1st computation.
b
2nd computation.
c
3rd computation.
d
4th computation.
e
5th computation.
g
6th computation.
h
7th computation.
i
8th computation.
f
Combination function.
Return Value
Result of combining the provided computations, in the context implementing this instance.
-
Combines the result of nine computations in the context implementing this instance, using the provided function.
This is a convenience method to call
Applicative.map
as a static method of this type.Declaration
Swift
static func map<B, C, D, E, G, H, I, J, Z>( _ a: Kind<F, Z>, _ b: Kind<F, B>, _ c: Kind<F, C>, _ d: Kind<F, D>, _ e: Kind<F, E>, _ g: Kind<F, G>, _ h: Kind<F, H>, _ i: Kind<F, I>, _ j: Kind<F, J>, _ f: @escaping (Z, B, C, D, E, G, H, I, J) -> A) -> Kind<F, A>
Parameters
a
1st computation.
b
2nd computation.
c
3rd computation.
d
4th computation.
e
5th computation.
g
6th computation.
h
7th computation.
i
8th computation.
j
9th computation.
f
Combination function.
Return Value
Result of combining the provided computations, in the context implementing this instance.
-
Lifts an error to the context implementing this instance.
This is a convenience method to call
ApplicativeError.raiseError
as a static method of this type.Declaration
Swift
static func raiseError(_ e: F.E) -> Kind<F, A>
Parameters
e
A value of the error type.
Return Value
A value representing the error in the context implementing this instance.
-
Handles an error, potentially recovering from it by mapping it to a value in the context implementing this instance.
This is a convenience method to call
ApplicativeError.handleErrorWith
as an instance method of this type.Declaration
Swift
func handleErrorWith(_ f: @escaping (F.E) -> Kind<F, A>) -> Kind<F, A>
Parameters
f
A recovery function.
Return Value
A value where the possible errors have been recovered using the provided function.
-
Handles an error, potentially recovering from it by mapping it to a value.
This is a convenience method to call
ApplicativeError.handleError
as an instance method of this type.Declaration
Swift
func handleError(_ f: @escaping (F.E) -> A) -> Kind<F, A>
Parameters
f
A recovery function.
Return Value
A value where the possible errors have been recovered using the provided function.
-
Handles errors by converting them into
Either
values in the context implementing this instance.This is a convenience method to call
ApplicativeError.attempt
as an instance method of this type.Declaration
Swift
func attempt() -> Kind<F, Either<F.E, A>>
Return Value
An either wrapped in the context implementing this instance.
-
Converts an
Either
value into a value in the context implementing this instance.This is a convenience method to call
ApplicativeError.fromEither
as a static method of this type.Declaration
Swift
static func fromEither(_ fea: Either<F.E, A>) -> Kind<F, A>
Parameters
fea
An
Either
value.Return Value
A value in the context implementing this instance.
-
Converts an
Option
value into a value in the context implementing this instance.Declaration
Swift
static func fromOption(_ oa: Option<A>, _ f: () -> F.E) -> Kind<F, A>
Parameters
oa
An
Option
value.f
A function providing the error value in case the option is empty.
Return Value
A value in the context implementing this instance.
-
Converts a
Try
value into a value in the context implementing this instance.Declaration
Swift
static func fromTry(_ ta: Try<A>, _ f: (Error) -> F.E) -> Kind<F, A>
Parameters
ta
A
Try
value.f
A function transforming the error contained in
Try
to the error type of this instance.Return Value
A value in the context implementing this instance.
-
Evaluates a throwing function, catching and mapping errors.
This is a convenience method to call
ApplicativeError.catchError
as a static method of this type.Declaration
Swift
static func catchError(_ f: () throws -> A, _ recover: (Error) -> F.E) -> Kind<F, A>
Parameters
f
A throwing function.
recover
A function that maps from
Error
to the type that this instance is able to handle.Return Value
A value in the context implementing this instance.
-
Evaluates a throwing function, catching errors.
This is a convenience method to call
ApplicativeError.catchError
as a static method of this type.Declaration
Swift
static func catchError(_ f: () throws -> A) -> Kind<F, A>
Parameters
f
A throwing function.
Return Value
A value in the context implementing this instance.
-
Applies this value to a function that takes a value in this context, and returns a normal value.
This function is the dual of
Monad.flatMap
.This is a convenience function to call
Comonad.coflatMap
as an instance method.Declaration
Swift
func coflatMap<B>(_ f: @escaping (Kind<F, A>) -> B) -> Kind<F, B>
Parameters
f
Extracting function.
Return Value
The result of extracting and transforming the value, in the context implementing this instance.
-
Extracts the value contained in this context.
This function is the dual of
Monad.pure
(viaApplicative
).This is a convenience function to call
Comonad.extract
as an instance method.Declaration
Swift
func extract() -> A
Return Value
A normal value.
-
Wraps this in another layer of this context.
Declaration
Swift
func duplicate() -> Kind<F, Kind<F, A>>
Return Value
This value wrapped in another context layer.
-
Gets the underlying global environment from this value.
Declaration
Swift
func ask() -> F.E
Return Value
Global environment.
-
Obtains a value that depends on the environment.
Declaration
Swift
func asks<EE>(_ f: @escaping (F.E) -> EE) -> EE
Parameters
f
Function to obtain a value from the environment.
Return Value
A value that depends on the environment.
-
Transforms the environment into a local one.
Declaration
Swift
func local(_ f: @escaping (F.E) -> F.E) -> Kind<F, A>
Parameters
f
Transforming function.
Return Value
A value with the transformed environment.
-
Obtains the current position of the store.
Declaration
Swift
var position: F.S { get }
-
Obtains the value stored in the provided position.
Declaration
Swift
func peek(_ s: F.S) -> A
Parameters
s
Position within the Store.
Return Value
Value stored in the provided position.
-
Obtains a value in a position relative to the current position.
Declaration
Swift
func peeks(_ f: @escaping (F.S) -> F.S) -> A
Parameters
f
Function to compute the relative position.
Return Value
Value located in a relative position to the current one.
-
Moves to a new position.
Declaration
Swift
func seek(_ s: F.S) -> Kind<F, A>
Parameters
s
New position.
Return Value
Store focused into the new position.
-
Moves to a new position relative to the current one.
Declaration
Swift
func seeks(_ f: @escaping (F.S) -> F.S) -> Kind<F, A>
Parameters
f
Function to compute the new position, relative to the current one.
Return Value
Store focused into the new position.
-
Extracts a collection of values from positions that depend on the current one.
Declaration
Swift
func experiment<G: Functor>(_ f: @escaping (F.S) -> Kind<G, F.S>) -> Kind<G, A>
Parameters
f
Effectful function computing new positions based on the current one.
Return Value
A collection of values located a the specified positions.
-
Extracts a value at the specified relative position.
Declaration
Swift
func trace(_ m: F.M) -> A
Parameters
m
Relative position.
Return Value
Value corresponding to the specified position.
-
Extracts a value at a relative position which depends on the current value.
Declaration
Swift
func traces(_ f: @escaping (A) -> F.M) -> A
Parameters
f
Function to compute the position based on the current value.
Return Value
Value corresponding to the new position.
-
Gets a value that depends on the current position.
Declaration
Swift
func listens<B>(_ f: @escaping (F.M) -> B) -> Kind<F, (B, A)>
Parameters
f
Function to compute a value from the current position.
Return Value
A tuple with the current and computed value in the context of this ComonadTraced.
-
Obtains the current position together with the current value.
Declaration
Swift
func listen() -> Kind<F, (F.M, A)>
Return Value
A tuple with the current position and value in the context of this ComonadTraced.
-
Apply a function to the current position.
Declaration
Swift
func censor(_ f: @escaping (F.M) -> F.M) -> Kind<F, A>
Parameters
f
Function to transform the current position.
Return Value
Trace focused in the new position.
-
Obtains a Trace that can modify the current position.
Declaration
Swift
func pass() -> Kind<F, ((F.M) -> F.M) -> A>
Return Value
Trace that can modify the current position.
-
Obtains the comonadic value contained in the provided comonad transformer.
Declaration
Swift
func lower() -> Kind<F.W, A>
Return Value
Contained comonadic value within the transformer.
-
Creates a new value transforming the type using the provided function, preserving the structure of the original type.
Declaration
Swift
func contramap<B>(_ f: @escaping (B) -> A) -> Kind<F, B>
Parameters
f
Transforming function.
Return Value
The result of transforming the value type using the provided function, maintaining the structure of the original value.
-
Given a function, provides a new function lifted to the context type implementing this instance of
Contravariant
, but reversing the direction of the arrow.Declaration
Swift
static func contralift<B>(_ f: @escaping (A) -> B) -> (Kind<F, B>) -> Kind<F, A>
Parameters
f
Function to be lifted.
Return Value
Function in the context implementing this instance.
-
Takes 2 computations and produces a new one that decides which one will be run, based on a provided function.
Declaration
Swift
static func choose<B, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ f: (A) -> Either<Z, B>) -> Kind<F, A>
Parameters
fa
1st computation
fb
2nd computation
f
Deciding function
Return Value
A computation that decides which of the provided arguments should run.
-
Takes 3 computations and produces a new one that decides which one will be run, based on a provided function.
Declaration
Parameters
fa
1st computation
fb
2nd computation
fc
3rd computation
f
Deciding function
Return Value
A computation that decides which of the provided arguments should run.
-
Takes 4 computations and produces a new one that decides which one will be run, based on a provided function.
Declaration
Parameters
fa
1st computation
fb
2nd computation
fc
3rd computation
fd
4th computation
f
Deciding function
Return Value
A computation that decides which of the provided arguments should run.
-
Takes 5 computations and produces a new one that decides which one will be run, based on a provided function.
Declaration
Parameters
fa
1st computation
fb
2nd computation
fc
3rd computation
fd
4th computation
fe
5th computation
f
Deciding function
Return Value
A computation that decides which of the provided arguments should run.
-
Takes 6 computations and produces a new one that decides which one will be run, based on a provided function.
Declaration
Parameters
fa
1st computation
fb
2nd computation
fc
3rd computation
fd
4th computation
fe
5th computation
ff
6th computation
f
Deciding function
Return Value
A computation that decides which of the provided arguments should run.
-
Takes 7 computations and produces a new one that decides which one will be run, based on a provided function.
Declaration
Parameters
fa
1st computation
fb
2nd computation
fc
3rd computation
fd
4th computation
fe
5th computation
ff
6th computation
fg
7th computation
f
Deciding function
Return Value
A computation that decides which of the provided arguments should run.
-
Takes 8 computations and produces a new one that decides which one will be run, based on a provided function.
Declaration
Swift
static func choose<B, C, D, E, FF, G, H, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ ff: Kind<F, FF>, _ fg: Kind<F, G>, _ fh: Kind<F, H>, _ f: (A) -> Either<Z, Either<B, Either<C, Either<D, Either<E, Either<FF, Either<G, H>>>>>>> ) -> Kind<F, A>
Parameters
fa
1st computation
fb
2nd computation
fc
3rd computation
fd
4th computation
fe
5th computation
ff
6th computation
fg
7th computation
fh
8th computation
f
Deciding function
Return Value
A computation that decides which of the provided arguments should run.
-
Takes 9 computations and produces a new one that decides which one will be run, based on a provided function.
Declaration
Swift
static func choose<B, C, D, E, FF, G, H, I, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ ff: Kind<F, FF>, _ fg: Kind<F, G>, _ fh: Kind<F, H>, _ fi: Kind<F, I>, _ f: (A) -> Either<Z, Either<B, Either<C, Either<D, Either<E, Either<FF, Either<G, Either<H, I>>>>>>>> ) -> Kind<F, A>
Parameters
fa
1st computation
fb
2nd computation
fc
3rd computation
fd
4th computation
fe
5th computation
ff
6th computation
fg
7th computation
fh
8th computation
fi
9th computation
f
Deciding function
Return Value
A computation that decides which of the provided arguments should run.
-
Takes 10 computations and produces a new one that decides which one will be run, based on a provided function.
Declaration
Swift
static func choose<B, C, D, E, FF, G, H, I, J, Z>( _ fa: Kind<F, Z>, _ fb: Kind<F, B>, _ fc: Kind<F, C>, _ fd: Kind<F, D>, _ fe: Kind<F, E>, _ ff: Kind<F, FF>, _ fg: Kind<F, G>, _ fh: Kind<F, H>, _ fi: Kind<F, I>, _ fj: Kind<F, J>, _ f: (A) -> Either<Z, Either<B, Either<C, Either<D, Either<E, Either<FF, Either<G, Either<H, Either<I, J>>>>>>>>> ) -> Kind<F, A>
Parameters
fa
1st computation
fb
2nd computation
fc
3rd computation
fd
4th computation
fe
5th computation
ff
6th computation
fg
7th computation
fh
8th computation
fi
9th computation
fj
10th computation
f
Deciding function
Return Value
A computation that decides which of the provided arguments should run.
-
Takes a computation and provides a computation using a function that specifies how to divide the returned type into the two provided types.
Declaration
Swift
func divide<B, C>(_ fb: Kind<F, B>, _ f: (C) -> (A, B)) -> Kind<F, C>
Parameters
fb
2nd computation.
f
Dividing function.
Return Value
A computation that merges the divided parts.
-
Provides an empty value for this Divisible instance
Declaration
Swift
static func conquer() -> Kind<F, A>
-
Checks if two kinds are equal, given that the enclosed value type conforms to
Equatable
.This is a convenience method to call
EquatableK.eq
as an instance method of this type.Declaration
Swift
func eq(_ rhs: Kind<F, A>) -> Bool
Parameters
lhs
Left hand side of the equality check.
rhs
Right hand side of the equality check.
Return Value
A boolean value indicating if the two values are equal or not.
-
Declaration
Swift
public static func == (lhs: Kind<F, A>, rhs: Kind<F, A>) -> Bool
-
Eagerly folds this value to a summary value from left to right.
Declaration
Swift
func foldLeft<B>( _ b: B, _ f: @escaping (B, A) -> B) -> B
Parameters
b
Initial value for the folding process.
f
Folding function.
Return Value
Summary value resulting from the folding process.
-
Reduces the elements of this structure down to a single value by applying the provided transformation and aggregation funtions in a left-associative manner.
Declaration
Swift
func reduceLeftToOption<B>( _ f: @escaping (A) -> B, _ g: @escaping (B, A) -> B) -> Option<B>
Parameters
f
Transforming function.
g
Folding function.
Return Value
Optional summary value resulting from the folding process. It will be an
Option.none
if the structure is empty, or a value if not. -
Reduces the elements of this structure down to a single value by applying the provided transformation and aggregation functions in a right-associative manner.
Declaration
Parameters
f
Transforming function.
g
Folding function.
Return Value
Optional summary value resulting from the folding process. It will be an
Option.none
if the structure is empty, or a value if not. -
Reduces the elements of this structure down to a single value by applying the provided aggregation function in a left-associative manner.
Declaration
Swift
func reduceLeftOption( _ f: @escaping (A, A) -> A) -> Option<A>
Parameters
f
Folding function.
Return Value
Optional summary value resulting from the folding process.
-
Reduces the elements of this structure down to a single value by applying the provided aggregation function in a right-associative manner.
Parameters
f
Folding function.
Return Value
Optional summary value resulting from the folding process.
-
Transforms the elements of this structure to a type with a
Monoid
instance and folds them using the empty and combine methods of suchMonoid
instance.Declaration
Swift
func foldMap<B: Monoid>(_ f: @escaping (A) -> B) -> B
Parameters
fa
Value to be transformed and folded.
f
Transforming function.
Return Value
Summary value resulting from the transformation and folding process.
-
Traverses this structure of values, transforming them with a provided function and discarding the result of its effect.
Declaration
Swift
func traverse_<G: Applicative, B>(_ f: @escaping (A) -> Kind<G, B>) -> Kind<G, Unit>
Parameters
f
Transforming function.
Return Value
Unit in the context of the effect of the result of the transforming function.
-
Traverses this structure of effects, performing them and discarding their result.
Declaration
Swift
func sequence_<G, AA>() -> Kind<G, Unit> where A : Kind<G, AA>, G : Applicative
Return Value
Unit in the context of the effects contained in the structure.
-
Looks for an element that matches a given predicate.
Declaration
Swift
func find(_ f: @escaping (A) -> Bool) -> Option<A>
Parameters
f
Predicate.
Return Value
A value if there is any that matches the predicate, or
Option.none
. -
Checks if any element in this structure matches a given predicate.
Declaration
Swift
func exists(_ predicate: @escaping (A) -> Bool) -> Bool
Parameters
predicate
Predicate.
Return Value
A boolean value indicating if any elements in the structure match the predicate.
-
Checks if all elements in this structure match a given predicate.
Declaration
Swift
func forall(_ predicate: @escaping (A) -> Bool) -> Bool
Parameters
predicate
Predicate.
Return Value
A boolean value indicating if all elements in the structure match the predicate.
-
Checks if this structure of values is empty.
Declaration
Swift
var isEmpty: Bool { get }
Return Value
false
if the structure contains any value,true
otherwise. -
Checks if this structure of values is not empty.
Declaration
Swift
var nonEmpty: Bool { get }
Return Value
true
if the structure contains any value,false
otherwise. -
Performs a monadic left fold from the source context to the target monad.
Declaration
Swift
func foldM<G: Monad, B>( _ b: B, _ f: @escaping (B, A) -> Kind<G, B>) -> Kind<G, B>
Parameters
b
Initial value for the fold.
f
Folding function.
Return Value
Summary value resulting from the folding process in the context of the target monad.
-
Performs a monadic left fold by mapping the values in this structure to ones in the target monad context and using the
Monoid
instance to combine them.Declaration
Parameters
f
Trasnforming function.
Return Value
Summary value resulting from the transformation and folding process in the context of the target monad.
-
Obtains a specific element of a structure of elements given its indexed position.
Declaration
Swift
func get(_ index: Int64) -> Option<A>
Parameters
index
Indexed position of the element to retrieve.
Return Value
A value if there is any at the given position, or
Option.none
otherwise. -
Counts how many elements this structure contains.
Declaration
Swift
var count: Int64 { get }
Return Value
An integer value with the count of how many elements are contained in the structure.
-
Undocumented
Declaration
Swift
func reduceK<G: MonoidK, B>() -> Kind<G, B> where A: Kind<G, B>
-
Folds this structure of values provided that its type has an instance of
Monoid
.It uses the monoid empty value as initial value and the combination method for the fold.
Declaration
Swift
func fold() -> A
Return Value
Summary value resulting from the folding process.
-
Folds this structure of values provided that its type has an instance of
Monoid
.It uses the monoid empty value as initial value and the combination method for the fold.
Declaration
Swift
func combineAll() -> A
Return Value
Summary value resulting from the folding process.
-
Creates a new value transforming the type using the provided function, preserving the structure of the original type.
This is a convenience method to call
Functor.map
as an instance method in this type.Declaration
Swift
func map<B>(_ f: @escaping (A) -> B) -> Kind<F, B>
Parameters
f
A transforming function.
Return Value
The result of transforming the value type using the provided function, maintaining the structure of the original value.
-
Given a function, provides a new function lifted to the context type implementing this instance of
Functor
.This is a convenience method to call
Functor.lift
as a static method in this type.Declaration
Swift
static func lift<A, B>(_ f: @escaping (A) -> B) -> (Kind<F, A>) -> Kind<F, B>
Parameters
f
Function to be lifted.
Return Value
Function in the context implementing this instance of
Functor
. -
Replaces the value type by the
Void
type.This is a convenience method to call
Functor.void
as an instance method of this type.Declaration
Swift
func void() -> Kind<F, ()>
Return Value
New value in the context implementing this instance of
Functor
, withVoid
as value type. -
Transforms the value type and pairs it with its original value.
This is a conveninence method to call
Functor.fproduct
as an instance method of is type.Declaration
Swift
func fproduct<B>(_ f: @escaping (A) -> B) -> Kind<F, (A, B)>
Parameters
f
Transforming function.
Return Value
A pair with the original value and its transformation, in the context of the original value.
-
Transforms the value type with a constant value.
This is a convenience method to call
Functor.as
as an instance method of this type.Declaration
Swift
func `as`<B>(_ b: B) -> Kind<F, B>
Parameters
b
Constant value to replace the value type.
Return Value
A new value with the structure of the original value, with its value type transformed.
-
Transforms the value type by making a tuple with a new constant value to the left of the original value type.
This is a conveninence method to call
Functor.tupleLeft
as an instance method of this type.Declaration
Swift
func tupleLeft<B>(_ b: B) -> Kind<F, (B, A)>
Parameters
b
Constant value for the tuple.
Return Value
A new value with the structure of the original value, with a tuple in its value type.
-
Transforms the value type by making a tuple with a new constant value to the right of the original value type.
This is a convenience method to call
Functor.tupleRight
as an instance method of this type.Declaration
Swift
func tupleRight<B>(_ b: B) -> Kind<F, (A, B)>
Parameters
b
Constant value for the tuple.
Return Value
A new value with the structure of the original value, with a tuple in its value type.
-
Maps the value/s in the context implementing this instance, filtering out the ones resulting in
Option.none
.This is a convenience method to call
FunctorFilter.mapFilter
as an instance method of this type.Declaration
Swift
func mapFilter<B>(_ f: @escaping (A) -> OptionOf<B>) -> Kind<F, B>
Parameters
f
A function to map objects and filter them out.
Return Value
Transformed and filtered values, in this context.
-
Removes the
Option.none
value/s in this context and extracts theOption.some
ones.This is a convenience method to call
FunctorFilter.flattenOption
as a static method of this type.Declaration
Swift
static func flattenOption(_ fa: Kind<F, OptionOf<A>>) -> Kind<F, A>
Parameters
fa
Optional values in this context.
Return Value
Plain values in this context.
-
Filters out the value/s in this context that do not match the given predicate.
This is a convenience method to call
FunctorFilter.filter
as a static method of this type.Declaration
Swift
func filter(_ f: @escaping (A) -> Bool) -> Kind<F, A>
Parameters
f
Filtering predicate.
Return Value
Filtered value in this context.
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
-
Transforms the value type using the functions provided.
This is a conveninece method to call
Invariant.imap
as an instance method.Declaration
Swift
func imap<B>(_ f: @escaping (A) -> B, _ g: @escaping (B) -> A) -> Kind<F, B>
Parameters
f
Transforming function.
g
Transforming function.
Return Value
A new value in the same context as the original value, with the value type transformed.
-
Sequentially compose this computation with another one, passing any value produced by the first as an argument to the second.
This is a convenience method to call
Monad.flatMap
as an instance method of this type.Declaration
Swift
func flatMap<B>(_ f: @escaping (A) -> Kind<F, B>) -> Kind<F, B>
Parameters
f
A function describing the second computation, which depends on the value of the first.
Return Value
Result of composing the two computations.
-
Monadic tail recursion.
This is a convenience method to call
Monad.tailRecM
as a static method of this type.Declaration
Swift
static func tailRecM<B>( _ a: A, _ f: @escaping (A) -> Kind<F, Either<A, B>>) -> Kind<F, B>
Parameters
a
Initial value for the recursion.
f
A function describing a recursive step.
Return Value
Result of evaluating recursively the provided function with the initial value.
-
A stack safe version of
flatMap
, based ontailRecM
.Declaration
Swift
func stackSafeFlatMap<B>(_ f: @escaping (A) -> Kind<F, B>) -> Kind<F, B>
Parameters
f
A function describing the second computation, which depends on the value of the first.
Return Value
Result of composing the two computations.
-
Flattens a nested structure of the context implementing this instance into a single layer.
This is a convenience method to call
Monad.flatten
as a static method of this type.Declaration
Swift
func flatten<AA>() -> Kind<F, AA> where A == Kind<F, AA>
Parameters
ffa
Value with a nested structure.
Return Value
Value with a single context structure.
-
Sequentially compose with another computation, discarding the value produced by the this one.
This is a convenience method to call
Monad.followedBy
as an instance method of this type.Declaration
Swift
func followedBy<B>(_ fb: Kind<F, B>) -> Kind<F, B>
Parameters
fb
A computation.
Return Value
Result of running the second computation after the first one.
-
Sequentially compose this computation with a potentially lazy one, discarding the value produced by this one.
This is a convenience method to call
Monad.followedByEval
as an instance method of this type.Declaration
Swift
func followedByEval<B>(_ fb: Eval<Kind<F, B>>) -> Kind<F, B>
Parameters
fb
Lazy computation.
Return Value
Result of running the second computation after the first one.
-
Sequentially compose with another computation, discarding the value produced by the received one.
This is a convenience method to call
Monad.forEffect
as an instance method of this type.Declaration
Swift
func forEffect<B>(_ fb: Kind<F, B>) -> Kind<F, A>
Parameters
fb
A computation.
Return Value
Result produced from the first computation after both are computed.
-
Sequentially compose with a potentially lazy computation, discarding the value produced by the received one.
This is a convenience method to call
Monad.forEffectEval
as an instance method of this type.Declaration
Swift
func forEffectEval<B>(_ fb: Eval<Kind<F, B>>) -> Kind<F, A>
Parameters
fb
Lazy computation.
Return Value
Result produced from the first computation after both are computed.
-
Pair the result of this computation with the result of applying a function to such result.
This is a convenience method to call
Monad.mproduct
as an instance method.Declaration
Swift
func mproduct<B>(_ f: @escaping (A) -> Kind<F, B>) -> Kind<F, (A, B)>
Parameters
f
A function to be applied to the result of the computation.
Return Value
A tuple of the result of this computation paired with the result of the function, in the context implementing this instance.
-
Applies a monadic function and discard the result while keeping the effect.
Declaration
Swift
func flatTap<B>(_ f: @escaping (A) -> Kind<F, B>) -> Kind<F, A>
Parameters
f
A monadic function which result will be discarded.
Return Value
A computation with the result of the initial computation and the effect caused by the function application.
-
Conditionally apply a closure based on the boolean result of this computation.
This is a convenience method to call
Monad.ifM
as an instance method.Declaration
Swift
func ifM<B>( _ ifTrue: @escaping () -> Kind<F, B>, _ ifFalse: @escaping () -> Kind<F, B>) -> Kind<F, B>
Parameters
ifTrue
Closure to be applied if the computation evaluates to
true
.ifFalse
Closure to be applied if the computation evaluates to
false
.Return Value
Result of applying the corresponding closure based on the result of the computation.
-
Fold over the inner structure to combine all of the values with our combine method inherited from `MonoidK.
This is a convenience method to call
MonadCombine.unite
as a static method of this type.Declaration
Swift
static func unite<G>(_ fga: Kind<F, Kind<G, A>>) -> Kind<F, A> where G : Foldable
Parameters
fga
Nested contexts value.
Return Value
A value in the context implementing this instance where the inner context has been folded.
-
Creates a bound variable in the monadic context of this kind for the specified type.
Declaration
Swift
static func `var`() -> BoundVar<F, A>
Return Value
A bound variable.
-
Checks if the value of this computation matches a predicate, raising an error if not.
This is a convenience method to call
MonadError.ensure
as an instance method of this type.Declaration
Swift
func ensure( _ error: @escaping () -> F.E, _ predicate: @escaping (A) -> Bool) -> Kind<F, A>
Parameters
error
A function that produces an error of the type this instance is able to handle.
predicate
A boolean predicate to test the value of the computation.
Return Value
A value or an error in the context implementing this instance.
-
Applies a monadic function to an effect discarding the output.
Declaration
Swift
func flatTapError<B>(_ f: @escaping (F.E) -> Kind<F, B>) -> Kind<F, A>
Parameters
f
A monadic function which result will be discarded.
Return Value
A computation with the effect of the initial computation.
-
Obtains an empty element in this context.
Declaration
Swift
static var empty: Kind<F, A> { get }
Return Value
Empty element.
-
Retrieves the shared environment.
This is a convenience method to call
MonadReader.ask
as a static method of this type.Declaration
Swift
static func ask() -> Kind<F, F.D>
Return Value
Shared environment.
-
Executes this computation in a modified environment.
This is a convenience method to call
MonadReader.local
as an instance method of this type.Declaration
Swift
func local(_ f: @escaping (F.D) -> F.D) -> Kind<F, A>
Parameters
f
Funtion to modify the environment.
Return Value
Computation in the modified environment.
-
Retrieves a function of the current environment.
This is a convenience method to call
MonadReader.reader
as a static method of this type.Declaration
Swift
static func reader(_ f: @escaping (F.D) -> A) -> Kind<F, A>
Parameters
f
Selector function to apply to the environment.
Return Value
A value extracted from the environment, in the context implementing this instance.
-
Replaces the state inside the monad.
This is a convenience method to call
MonadState.set
as a static method of this type.Declaration
Swift
static func set(_ s: F.S) -> Kind<F, ()>
Parameters
s
New state.
Return Value
Unit.
-
Modifies the internal state.
This is a convenience method to call
MonadState.modify
as a static method of this type.Declaration
Swift
static func modify(_ f: @escaping (F.S) -> F.S) -> Kind<F, ()>
Parameters
f
Function that modifies the state.
Return Value
Unit.
-
Retrieves the state from the internals of the monad.
This is a convenience method to call
MonadState.get
as a static method of this type.Declaration
Swift
static func get() -> Kind<F, F.S>
Return Value
Maintained state.
-
Embeds a state action into the monad.
This is a convenience method to call
MonadState.state
as a static method of this type.Declaration
Swift
static func state(_ f: @escaping (F.S) -> (F.S, A)) -> Kind<F, A>
Parameters
f
A function that receives the state and computes a value and a new state.
Return Value
A value with the output of the function and the new state.
-
Retrieves a specific component of the state.
This is a convenience method to call
MonadState.inspect
as a static method of this type.Declaration
Swift
static func inspect(_ f: @escaping (F.S) -> A) -> Kind<F, A>
Parameters
f
Projection function to obtain part of the state.
Return Value
A specific part of the state.
-
Lift a computation from the F monad to this monad.
Declaration
Swift
static func liftF(_ fa: Kind<F.F, A>) -> Kind<F, A>
-
Produces a new value of the side stream of data.
This is a convenience method to call
MonadWriter.tell
as a static method of this type.Declaration
Swift
static func tell(_ w: F.W) -> Kind<F, ()>
Parameters
w
New value.
Return Value
Unit.
-
Embeds a writer action.
This is a convenience method to call
MonadWriter.writer
as a static method of this type.Declaration
Swift
static func writer(_ aw: (F.W, A)) -> Kind<F, A>
Parameters
aw
A tupe of the writer type and a value.
Return Value
The writer action embedded in the context implementing this instance.
-
Adds the side stream of data to the result of this computation.
This is a convenience method to call
MonadWriter.listen
as an instance method of this type.Declaration
Swift
func listen() -> Kind<F, (F.W, A)>
Return Value
The result of the computation paired with the side stream of data.
-
Performs a computation and transforms the side stream of data.
This is a convenience method to call
MonadWriter.pass
as a static method of this type.Declaration
Swift
static func pass(_ fa: Kind<F, ((F.W) -> F.W, A)>) -> Kind<F, A>
Parameters
fa
A computation that transform the stream of data.
Return Value
Result of the computation.
-
Performs this computation and transforms the side stream of data, pairing it with the result of this computation.
This is a convenience method to call
MonadWriter.listens
as an instance method of this type.Declaration
Swift
func listens<B>(_ f: @escaping (F.W) -> B) -> Kind<F, (B, A)>
Parameters
f
A function to transform the side stream of data.
Return Value
A tuple of the transformation of the side stream and the result of the computation.
-
Transforms the side stream of data of this computation.
This is a convenience method to call
MonadWriter.censor
as an instance method of this type.Declaration
Swift
func censor(_ f: @escaping (F.W) -> F.W) -> Kind<F, A>
Parameters
f
Transforming function.
Return Value
A computation with the same result as the provided one, with the transformed side stream of data.
-
Empty element.
This element must obey the following laws:
combineK(fa, emptyK()) == combineK(emptyK(), fa) == fa
This is a convenience method to call
MonoidK.emptyK
as a static method of this type.Declaration
Swift
static func emptyK() -> Kind<F, A>
Return Value
A value representing the empty element of this MonoidK instance.
-
Undocumented
Declaration
Swift
static func identity() -> Kind<F, A>
-
Divides this structure of values into a tuple that represents the first value of the structure (first component of the tuple) and the rest of values of the structure (second component of the tuple)
Declaration
Swift
func split() -> (A, Kind<F.G, A>)
Return Value
Tuple containing the first and rest of values in the structure.
-
Eagerly reduces this structure of values from left to right, also performing a transformation of values.
Declaration
Swift
func reduceLeftTo<B>( _ f: (A) -> B, _ g: (B, A) -> B) -> B
Parameters
f
Transforming function.
g
Folding function.
Return Value
Summary value of this reduction.
-
Lazily reduces this structure of values from right to left, also performing a transformation of values.
Parameters
f
Transforming function.
g
Folding function.
Return Value
Potentially lazy summary value of this reduction.
-
Reduces this structure of values to a summary value using the combination capabilities of the
Semigroup
instance of the underlying type.Declaration
Swift
func reduce() -> A
Return Value
Summary value of this reduction.
-
Conditionally applies a computation based on the result of this computation.
Declaration
Swift
func select<AA, B>(_ f: Kind<F, (AA) -> B>) -> Kind<F, B> where A == Either<AA, B>
Parameters
f
A computation that is executed in case the receiving computation evaluates to a left value.
Return Value
Composition of the two computations.
-
Evaluates one out of two computations based on the result of this computation.
Declaration
Swift
func branch<AA, B, C>(ifLeft fa: Kind<F, (AA) -> C>, ifRight fb: Kind<F, (B) -> C>) -> Kind<F, C> where A == Either<AA, B>
Parameters
ifLeft
Computation that will be executed if this computation evaluates to an
Either.left
value.ifRight
Computation that will be executed if this computation evaluates to an
Either.right
value.Return Value
Composition of the computations.
-
Declaration
Swift
func fromOptionS<AA>(defaultValue x: Kind<F, AA>) -> Kind<F, AA> where A == Option<AA>
Parameters
defaultValue
Default value for the empty case.
Return Value
Composition of the two computations.
-
Evaluates the second computation when this evaluates to
true
.Declaration
Swift
func whenS(then f: Kind<F, ()>) -> Kind<F, ()>
Parameters
then
A computation that will be evaluated if the first computation evaluates to
true
.Return Value
Composition of the two computations.
-
Evaluates one out of two computations based on the result of another computation.
Declaration
Swift
func ifS<A>(then t: Kind<F, A>, else e: Kind<F, A>) -> Kind<F, A>
Parameters
then
Computation that will be executed if this evaluates to
true
.else
Computation that will be executed if this evaluates to
false
.Return Value
Composition of the computations.
-
A lifted version of lazy boolean or.
Declaration
Swift
func orS(_ y: Kind<F, Bool>) -> Kind<F, Bool>
Parameters
y
Computation to be or'ed.
Return Value
Result of the or operation on the two computations.
-
A lifted version of lazy boolean and.
Declaration
Swift
func andS(_ y: Kind<F, Bool>) -> Kind<F, Bool>
Parameters
y
Computation to be and'ed.
Return Value
Result of the and operation on the two computations.
-
Evaluates this computation as long as it evaluates to
true
.Declaration
Swift
func whileS() -> Eval<Kind<F, ()>>
Return Value
A potentially lazy computation.
-
Combines this value with another value of the same type.
This is a convenience method to call
SemigroupK.combineK
as an instance method of this type.Declaration
Swift
func combineK(_ y: Kind<F, A>) -> Kind<F, A>
Parameters
y
Right value in the combination.
Return Value
Combination of the two values.
-
Multiplicatively combine F and F into F<(A, B)>
This is a convenience method to call
Semigroupal.product
as an instance method of this type.Declaration
Swift
func product<B>(_ y: Kind<F, B>) -> Kind<F, (A, B)>
Parameters
y
Right value.
Return Value
Cartesian product of the two values.
-
Maps each element of this structure to an effect, evaluates them from left to right and collects the results.
Declaration
Swift
func traverse<G: Applicative, B>(_ f: @escaping (A) -> Kind<G, B>) -> Kind<G, Kind<F, B>>
Parameters
f
A function producing an effect.
Return Value
Results collected under the context of the effect provided by the function.
-
Evaluate each effect in this structure of values and collects the results.
Declaration
Swift
func sequence<G: Applicative, AA>() -> Kind<G, Kind<F, AA>> where A: Kind<G, AA>
Return Value
Results collected under the context of the effects.
-
A traverse followed by flattening the inner result.
Declaration
Swift
func flatTraverse<G: Applicative, B>(_ f: @escaping (A) -> Kind<G, Kind<F, B>>) -> Kind<G, Kind<F, B>>
Parameters
f
A transforming function yielding nested effects.
Return Value
Results collected and flattened under the context of the effects.
-
Maps each element of this structure using a stateful function.
Declaration
Swift
func scanLeft<B, S>( initialState: S, f: @escaping (A) -> State<S, B>) -> Kind<F, B>
Parameters
initialState
The state that will be passed to f initially.
f
A stateful function.
Return Value
A new structure with the results of the function.
-
Maps each element of this structure using a stateful function.
Declaration
Swift
func scanLeft<B>( initialState: B, f: @escaping (B, A) -> B) -> Kind<F, B>
Parameters
initialState
The state that will be passed to f initially.
f
A stateful function that returns the new state, which will be included in the returned structure.
Return Value
A new structure with the results of the function.
-
Maps each element of this structure to an effect using a stateful function.
Declaration
Parameters
initialState
The state that will be passed to f initially.
f
A stateful function producing an effect.
Return Value
Results collected under the context of the effect provided by the function.
-
Maps each element of this structure to an effect using a stateful function.
Declaration
Swift
func scanLeftM<M: Monad, B>( initialState: Kind<M, B>, f: @escaping (B, A) -> Kind<M, B>) -> Kind<M, Kind<F, B>>
Parameters
initialState
The state that will be passed to f initially.
f
A stateful function producing an effect, which will be included in the returned structure.
Return Value
Results collected under the context of the effect provided by the function.
-
A combined traverse and filter operation. Filtering is handled using
Option
instead of Bool so that the output can be different than the input type.This is a convenience method to call
TraverseFilter.traverseFilter
as an instance method of this type.Declaration
Swift
func traverseFilter<B, G: Applicative>(_ f: @escaping (A) -> Kind<G, OptionOf<B>>) -> Kind<G, Kind<F, B>>
Parameters
fa
A value in this context.
f
A function to traverse and filter each value.
Return Value
Result of traversing this structure and filter values using the provided function.
-
Filters values in a different context.
This is a convenience method to call
TraverseFilter.filterA
as an instance method of this type.Declaration
Swift
func filterA<G: Applicative>(_ f: @escaping (A) -> Kind<G, Bool>) -> Kind<G, Kind<F, A>>
Parameters
fa
A value in this context.
f
A function to filter each value.
Return Value
Result of traversing this structure and filter values using the provided function.