arrow-kt / arrow

Λrrow - Functional companion to Kotlin's Standard Library
http://arrow-kt.io
Other
6.19k stars 448 forks source link

Request documentation about concepts of the FP ladder in Arrow #1803

Closed jabrena closed 3 years ago

jabrena commented 5 years ago

What version are you currently using?

LATEST

What would you like to see?

When you are trying to review the first 2 levels of the Open ladder of functional programming using Kotlin and Arrow, I don´t find many examples in the documentation about the following topics:

Steps:

Juan Antonio

raulraja commented 5 years ago

These came mostly from funktionale before Kategory and funktionale merged into Arrow and nobody has taken the time to document those. @jabrena Feel free to take on it if you want, descriptions for what these functions do are everywhere in the internet

jabrena commented 5 years ago

Oki, next week I will start from the first feature where Arrow add some features

Level 1
 - Immutable Data
 - Second-Order Functions
 - Constructoring & Destructuring
 - Function Composition <-- Starting point
 - First-Class Functions & Lambdas

Files affected:

Juan Antonio

PhBastiani commented 5 years ago

See also #802

jabrena commented 5 years ago

Working on the issue.

jabrena commented 5 years ago

Initial documentation process for file: composition.kt

package arrow.syntax.function

inline infix fun <P1, P2, IP, R> ((P1, P2) -> IP).andThen(crossinline f: (IP) -> R) = forwardCompose(f)

inline infix fun <P1, IP, R> ((P1) -> IP).andThen(crossinline f: (IP) -> R): (P1) -> R = forwardCompose(f)

inline infix fun <IP, R> (() -> IP).andThen(crossinline f: (IP) -> R): () -> R = forwardCompose(f)

inline infix fun <P1, P2, IP, R> ((P1, P2) -> IP).forwardCompose(crossinline f: (IP) -> R) = { p1: P1, p2: P2 -> f(this(p1, p2)) }

inline infix fun <P1, IP, R> ((P1) -> IP).forwardCompose(crossinline f: (IP) -> R): (P1) -> R = { p1: P1 -> f(this(p1)) }

inline infix fun <IP, R> (() -> IP).forwardCompose(crossinline f: (IP) -> R): () -> R = { f(this()) }

inline infix fun <IP, R, P1> ((IP) -> R).compose(crossinline f: (P1) -> IP): (P1) -> R = { p1: P1 -> this(f(p1)) }
jabrena commented 5 years ago

Good morning,

What is the difference between: AndThen from arrow-core: https://arrow-kt.io/docs/apidocs/arrow-core-data/arrow.core/-and-then/index.html

and andThen from arrow.syntax.function?

What is the recommended way to use the functional composition in Arrow?

I have the impression that exist a way from the merge process from funktionale https://github.com/MarioAriasC/funKTionale/blob/master/funktionale-composition/src/main/kotlin/org/funktionale/composition/namespace.kt

and another way from the package arrow.syntax.function.

I need the clarify what is the recommended way.

jabrena commented 5 years ago

I detected that the original support for funktionale only support Functors with few parameters: https://github.com/MarioAriasC/funKTionale/blob/master/funktionale-composition/src/main/kotlin/org/funktionale/composition/namespace.kt

but in Arrow for Functors with more than 3 arguments, the library doesn´t support some features but the partial support is greater. https://github.com/arrow-kt/arrow/blob/master/modules/core/arrow-syntax/src/main/kotlin/arrow/syntax/function/composition.kt

Current documentation:

https://arrow-kt.io/docs/apidocs/arrow-syntax/arrow.syntax.function/kotlin.-function0/index.html https://arrow-kt.io/docs/apidocs/arrow-syntax/arrow.syntax.function/kotlin.-function1/index.html https://arrow-kt.io/docs/apidocs/arrow-syntax/arrow.syntax.function/kotlin.-function3/index.html ... https://arrow-kt.io/docs/apidocs/arrow-syntax/arrow.syntax.function/kotlin.-function22/index.html

The support for andThen and compose is not consistent for Functors 1-22

raulraja commented 3 years ago

Closing old issue as it is no longer relevant given Arrow's direction. Thanks @jabrena