New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve docs to better explain monads #956
Changes from 22 commits
cdae386
ad45074
519f7fe
322ff7b
db28f3e
39b756a
42a125f
1fba857
a1c70f8
67effee
be39c6a
65822e3
c25aca3
baec9a4
0ef582b
68eeeca
2779aa2
c8ee7da
47f6351
9314838
c946945
056d4ec
ae5b11d
66d1589
d2c4607
4adc3dc
7dbe192
1c75ffc
f4ade89
03a20c7
b637ad3
8103d3e
41f03d5
25b84f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,10 @@ NOTE: The docs are currently at around 60% completion. They're the present prior | |
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) | ||
|
||
Λrrow is a library for Typed Functional Programming in Kotlin. | ||
It includes the most popular data types, type classes and abstractions such as `Option`, `Try`, `Either`, `IO`, `Functor`, `Applicative`, `Monad` to empower users to define pure FP apps and libraries built atop higher order abstractions. | ||
|
||
Arrow aims to provide a *lingua franca* of interfaces and abstractions across Kotlin libraries. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to add the following and/or a link to Wikipedia:
|
||
For this, it includes the most popular data types, type classes and abstractions such as `Option`, `Try`, `Either`, `IO`, `Functor`, `Applicative`, `Monad` to empower users to define pure FP apps and libraries built atop higher order abstractions. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't use the term 'define'. I'd replace it with create and write 'to empower users to create pure FP applications and libraries built using higher order abstractions |
||
Use the list below to learn more about Λrrow's main features. | ||
|
||
- [Patterns](http://arrow-kt.io/docs/patterns/glossary/): tutorials and approaches to day-to-day challenges using FP | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ You can read more about all the [datatypes]({{ '/docs/datatypes/intro' | relativ | |
|
||
### Typeclasses | ||
|
||
Typeclasses define a set of functions associated to one type. | ||
Typeclasses define a set of extension functions associated to one type. | ||
This behavior is checked by a test suite called the "laws" for that typeclass. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also talking about implementation detail (test suite) and then talking about laws, without introducing the laws. Maybe it just makes sense to put the paragraph of learning more about typeclasses at the start. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rewritten! |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. believe this is an implementation detail or how it would be defined in Kotlin, as it's using the term extension function. I think it would be better to first introduce what the concept of typeclasses are. |
||
You can use typeclasses as a DSL to add new free functionality to an existing type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd explain what you mean by the use of "free" functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added! |
||
|
@@ -46,6 +46,9 @@ One example, the typeclass `Eq` parametrized to `F` defines equality between two | |
```kotlin | ||
interface Eq<F> { | ||
fun F.eqv(b: F): Boolean | ||
|
||
fun F.neqv(b: F): Boolean = | ||
!eqv(b) | ||
} | ||
``` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ permalink: /docs/patterns/monad_comprehensions/ | |
{:.intermediate} | ||
intermediate | ||
|
||
Monad comprehension is the name for a programming idiom available in multiple languages. | ||
Monad comprehension is the name for a programming idiom available in multiple languages like JavaScript, F#, Scala, or Haskell. | ||
The purpose of monad comprehensions is to compose sequential chains of actions in a style that feels natural for programmers of all backgrounds. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. either "a monad comprehension is" or "monad comprehensions are" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! |
||
|
||
### Synchronous sequences of actions | ||
|
@@ -37,12 +37,15 @@ They allow us to write sequenced code that can be run asynchronously over multip | |
|
||
### Asynchronous sequences of actions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't see a lead in here from Monad Comprehensions.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added one |
||
|
||
The general representation of sequenced execution in code is called a [`Monad`]({{ '/docs/typeclasses/monad' | relative_url }}). This typeclass is a short API for sequencing code, summarised in a single function `flatMap`. | ||
It takes as a parameter one function to be called after the current operation completes, and that function has to return another [`Monad`]({{ '/docs/typeclasses/monad' | relative_url }}) to continue the operation with. | ||
A common renaming of `flatMap` is `andThen`. Go to the documentation page to see a deep dive on the Monad API. | ||
|
||
The abstraction of sequencing execution of code is summarised in a single function that in Arrow is called `flatMap`, | ||
although you may find it in other languages referred as `andThen`, `then`, `bind`, or `SelectMany`. | ||
It takes as a parameter one function to be called after the current operation completes, and that function has to return another value to continue the operation with. | ||
With knowledge of `flatMap` we can write sequential expressions that are ran asynchronously, even over multiple threads. | ||
Implementations of `Monad` are available for internal types like `Try` and also integrations like [RxJava 2]({{ '/docs/integrations/rx2' | relative_url }}) and [kotlinx.coroutines]({{ '/docs/integrations/kotlinxcoroutines' | relative_url }}). | ||
|
||
The [typeclass]({{ '/docs/typeclasses/intro' | relative_url }}) interface that abstracts sequenced execution of code via `flatMap` is called a [`Monad`]({{ '/docs/typeclasses/monad' | relative_url }}), | ||
for which we also have a [tutorial]({{ '/docs/patterns/monads' | relative_url }}). | ||
|
||
Implementations of [`Monad`]({{ '/docs/typeclasses/monad' | relative_url }}) are available for internal types like `Try` and also integrations like [RxJava 2]({{ '/docs/integrations/rx2' | relative_url }}) and [kotlinx.coroutines]({{ '/docs/integrations/kotlinxcoroutines' | relative_url }}). | ||
Let's see one example using a [`Monad`]({{ '/docs/typeclasses/monad' | relative_url }}) called [`IO`]({{ '/docs/effects/io' | relative_url }}), where we fetch from a database the information about the dean of university some student attends: | ||
|
||
```kotlin | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[same as this]