Applicative
public protocol Applicative : Functor
An Applicative Functor is a Functor
that also provides functionality to lift pure expressions, and sequence computations and combine their results.
Instances of this typeclass must obey the following laws:
Identity
ap(pure(id), v) == v
Composition
ap(ap(ap(pure(compose), u), v), w) == compose(u, compose(v, w))
Homomorphism
ap(pure(f), pure(x)) == pure(f(x))
Interchange
ap(fa, pure(b)) == ap(pure({ x in x(a) }), fa)
-
Lifts a value to the context type implementing this instance of
Applicative
.Declaration
Swift
static func pure<A>(_ a: A) -> Kind<Self, A>
Parameters
a
Value to be lifted.
Return Value
Provided value in the context type implementing this instance.
-
Sequential application.
Declaration
Parameters
ff
A function in the context implementing this instance.
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.
-
zipRight(_:_:)
Extension methodSequentially compose two computations, discarding the value produced by the first.
Declaration
Parameters
fa
1st computation.
fb
2nd computation.
Return Value
Result of running the second computation after the first one.
-
zipLeft(_:_:)
Extension methodSequentially compose two computations, discarding the value produced by the second.
Declaration
Parameters
fa
1st computation.
fb
2nd computation.
Return Value
Result produced from the first computation after both are computed.
-
product(_:_:)
Extension methodCreates a tuple in the context implementing this instance from two values in the same context.
Declaration
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.
-
product(_:_:)
Extension methodAdds an element to the right of a tuple in the context implementing this instance.
Declaration
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.
-
product(_:_:)
Extension methodAdds an element to the right of a tuple in the context implementing this instance.
Declaration
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.
-
product(_:_:)
Extension methodAdds an element to the right of a tuple in the context implementing this instance.
Declaration
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.
-
product(_:_:)
Extension methodAdds an element to the right of a tuple in the context implementing this instance.
Declaration
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.
-
product(_:_:)
Extension methodAdds an element to the right of a tuple in the context implementing this instance.
Declaration
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.
-
product(_:_:)
Extension methodAdds an element to the right of a tuple in the context implementing this instance.
Declaration
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.
-
product(_:_:)
Extension methodAdds an element to the right of a tuple in the context implementing this instance.
Declaration
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.
-
map2Eval(_:_:_:)
Extension methodPerforms two computations in the context implementing this instance and combines their result using the provided function.
Declaration
Parameters
fa
A value in the context implementing this instance.
fb
A lazy value in the context implementing this instance.
f
A function to combine the result of the computations.
Return Value
A lazy value with the result of combining the results of each computation.
-
zip(_:_:)
Extension methodCreates a tuple out of two values in the context implementing this instance.
Declaration
Parameters
a
1st value of the tuple.
b
2nd value of the tuple.
Return Value
A tuple in the context implementing this instance.
-
zip(_:_:_:)
Extension methodCreates a tuple out of three values in the context implementing this instance.
Declaration
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.
-
zip(_:_:_:_:)
Extension methodCreates a tuple out of four values in the context implementing this instance.
Declaration
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.
-
zip(_:_:_:_:_:)
Extension methodCreates a tuple out of five values in the context implementing this instance.
Declaration
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.
-
zip(_:_:_:_:_:_:)
Extension methodCreates a tuple out of six values in the context implementing this instance.
Declaration
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.
-
zip(_:_:_:_:_:_:_:)
Extension methodCreates a tuple out of seven values in the context implementing this instance.
Declaration
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.
-
zip(_:_:_:_:_:_:_:_:)
Extension methodCreates a tuple out of eight values in the context implementing this instance.
Declaration
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.
-
zip(_:_:_:_:_:_:_:_:_:)
Extension methodCreates a tuple out of nine values in the context implementing this instance.
Declaration
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.
-
map(_:_:_:)
Extension methodCombines the result of two computations in the context implementing this instance, using the provided function.
Declaration
Parameters
a
1st computation.
b
2nd computation.
f
Combination function.
Return Value
Result of combining the provided computations, in the context implementing this instance.
-
map(_:_:_:_:)
Extension methodCombines the result of three computations in the context implementing this instance, using the provided function.
Declaration
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.
-
map(_:_:_:_:_:)
Extension methodCombines the result of four computations in the context implementing this instance, using the provided function.
Declaration
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.
-
map(_:_:_:_:_:_:)
Extension methodCombines the result of five computations in the context implementing this instance, using the provided function.
Declaration
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.
-
map(_:_:_:_:_:_:_:)
Extension methodCombines the result of six computations in the context implementing this instance, using the provided function.
Declaration
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.
-
map(_:_:_:_:_:_:_:_:)
Extension methodCombines the result of seven computations in the context implementing this instance, using the provided function.
Declaration
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.
-
map(_:_:_:_:_:_:_:_:_:)
Extension methodCombines the result of eight computations in the context implementing this instance, using the provided function.
Declaration
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.
-
map(_:_:_:_:_:_:_:_:_:_:)
Extension methodCombines the result of nine computations in the context implementing this instance, using the provided function.
Declaration
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.