Adds initial aliases.
This commit is contained in:
parent
f2ba9a5766
commit
2a590586d1
|
@ -9,7 +9,9 @@ let package = Package(
|
|||
// Products define the executables and libraries a package produces, and make them visible to other packages.
|
||||
.library(
|
||||
name: "AliasWonderland",
|
||||
targets: ["AliasWonderland"]),
|
||||
type: .dynamic,
|
||||
targets: ["AliasWonderland"]
|
||||
),
|
||||
],
|
||||
dependencies: [
|
||||
// Dependencies declare other packages that this package depends on.
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
|
||||
/// Asynchronus function returning some value.
|
||||
public typealias AsyncProducer<T> = () async -> T
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
// MARK: - Closure
|
||||
|
||||
/*:
|
||||
|
||||
Alias for function type. Makes signatures of higher order functions more managable.
|
||||
|
||||
*/
|
||||
|
||||
public typealias Closure<I, O> = (I) -> O
|
||||
public typealias Closure2I<I1,I2, O> = (I1, I2) -> O
|
||||
public typealias Closure3I<I1,I2,I3, O> = (I1, I2, I3) -> O
|
||||
public typealias Closure4I<I1,I2,I3,I4, O> = (I1, I2, I3, I4) -> O
|
||||
public typealias Closure5I<I1,I2,I3,I4,I5, O> = (I1, I2, I3, I4, I5) -> O
|
||||
public typealias Closure6I<I1,I2,I3,I4,I5,I6, O> = (I1, I2, I3, I4, I5, I6) -> O
|
||||
public typealias Closure7I<I1,I2,I3,I4,I5,I6,I7, O> = (I1, I2, I3, I4, I5, I6, I7) -> O
|
||||
public typealias Closure8I<I1,I2,I3,I4,I5,I6,I7, I8, O> = (I1, I2, I3, I4, I5, I6, I7, I8) -> O
|
||||
|
||||
// MARK: - Producer Closures
|
||||
/*:
|
||||
# Producers
|
||||
|
||||
Functions that can return an instacne of some type.
|
||||
*/
|
||||
|
||||
public typealias Producer<T> = Closure<SideEffect, T>
|
||||
|
||||
// MARK: Async
|
||||
|
||||
public typealias AsyncClosure<I, O> = (I) async -> O
|
||||
public typealias AsyncClosure2I<I1,I2, O> = (I1, I2) async -> O
|
||||
public typealias AsyncClosure3I<I1,I2,I3, O> = (I1, I2, I3) async -> O
|
||||
public typealias AsyncClosure4I<I1,I2,I3,I4, O> = (I1, I2, I3, I4) async -> O
|
||||
public typealias AsyncClosure5I<I1,I2,I3,I4,I5, O> = (I1, I2, I3, I4, I5) async -> O
|
||||
public typealias AsyncClosure6I<I1,I2,I3,I4,I5,I6, O> = (I1, I2, I3, I4, I5, I6) async -> O
|
||||
public typealias AsyncClosure7I<I1,I2,I3,I4,I5,I6,I7, O> = (I1, I2, I3, I4, I5, I6, I7) async -> O
|
||||
public typealias AsyncClosure8I<I1,I2,I3,I4,I5,I6,I7, I8, O> = (I1, I2, I3, I4, I5, I6, I7, I8) async -> O
|
||||
|
||||
/// Asynchronus function returning some value.
|
||||
public typealias AsyncProducer<T> = AsyncClosure<SideEffect, T>
|
|
@ -0,0 +1,42 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
/*:
|
||||
|
||||
# What is a side effect?
|
||||
|
||||
Each time you run some code for "change of the world" not for the returned value you
|
||||
are dealing with a side effect (sometimes functions do both). Good examples are:
|
||||
|
||||
- printing to a console
|
||||
- making a network request
|
||||
- change the state of some object (eg. change of background color)
|
||||
|
||||
Each function in Swift returns a value. Sometime this value is `Void` which signals
|
||||
that this function was run for some sort of side effect.
|
||||
|
||||
*/
|
||||
|
||||
public typealias SideEffect = Void
|
||||
|
||||
public typealias SideEffectClosure = () -> SideEffect
|
||||
|
||||
// MARK: - Consumers Closures
|
||||
|
||||
/*:
|
||||
|
||||
# What is a consumer?
|
||||
|
||||
It's a function that takes some input and performs `SideEffect`.
|
||||
Typicaly you can find them as many `handlers`.
|
||||
|
||||
*/
|
||||
|
||||
public typealias Consumer<I> = (I) -> SideEffect
|
||||
public typealias Consumer2I<I1,I2> = (I1, I2) -> SideEffect
|
||||
public typealias Consumer3I<I1,I2,I3> = (I1, I2, I3) -> SideEffect
|
||||
public typealias Consumer4I<I1,I2,I3,I4> = (I1, I2, I3, I4) -> SideEffect
|
||||
public typealias Consumer5I<I1,I2,I3,I4,I5> = (I1, I2, I3, I4, I5) -> SideEffect
|
||||
public typealias Consumer6I<I1,I2,I3,I4,I5,I6> = (I1, I2, I3, I4, I5, I6) -> SideEffect
|
||||
public typealias Consumer7I<I1,I2,I3,I4,I5,I6,I7> = (I1, I2, I3, I4, I5, I6, I7) -> SideEffect
|
||||
public typealias Consumer8I<I1,I2,I3,I4,I5,I6,I7, I8> = (I1, I2, I3, I4, I5, I6, I7, I8) -> SideEffect
|
Loading…
Reference in New Issue