What is Arrow? Companion to Kotlin's standard library enabling pure functional programming Not a new concept, but new to Kotlin/Android Pure Functional is to domain modeling as Kotlin native is to platform
What is Pure Functional? Programming process To model behaviour, are verbs/actions Only operate on input, and provide output Limited to functions scope
How do we work with Pure Functional? Reduce behaviour Use domain vocabulary Use immutable objects, state change requires a new object fun addOne(a:A) = A(a.num + 1)
Can my ADT compose/operate with your ADT? Yes, because we use Arrow’s abstractions They are generic container classes specifically to do this Arrow is modeling the domain of Category Theory
What is Category Theory? The mathematics of composition/morphisms Conceptual framework for structure/system of structures Has laws(associativity, identity) Arrows types(abstractions) obey these laws Operate on sets
Algebraic Data Types Not operating on values, but types sealed class MyBoolean{ fun and(other:MyBoolean):MyBoolean class MyTrue:MyBoolean(){...} class MyFalse:MyBoolean(){...} }
when(myBoolean){ is MyTrue -> {...} is MyFalse -> {...} } Compiler verifies type of our Algebraic Data Types Verified when passing as function input/output Now have referential transparency
Why? Logic is explicit, type safe/constrained The domain model is pure/encoded within the type system Project’s domain models(types/algebra) are a superset of the Arrows types/algebra We have a common language to describe computation
Why? Logic is explicit, type safe/constrained The domain model is pure/encoded within the type system Project’s domain models(types/algebra) are a superset of the Arrows types/algebra We have a common language to describe computation The domain algebra is decoupled from the projects implementation Ad-hoc polymorphism
Why? Logic is explicit, type safe/constrained The domain model is pure/encoded within the type system Project’s domain models(types/algebra) are a superset of the Arrows types/algebra We have a common language to describe computation The domain algebra is decoupled from the projects implementation Ad-hoc polymorphism (soon-ish KEEP#87)
Usage and To Solve fun myDomainBehaviour(a:AbstractionForSequentialComputation, b:AbstractionForComputationContainingDependencies, c:(AbstractionForParallelComputation) -> AbstractionForValidation):AbstractionThatReturnsOfMyType> { abstractionForIoOperation(abstractionForReactiveImplementation)(abstraction ForFrontEndUiEventRegardlessOfPlatform)