Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Disconnect arrow-incubator #91

Merged
merged 13 commits into from Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion arrow-docs/build.gradle
Expand Up @@ -17,7 +17,7 @@ apply from: "$SUB_PROJECT"
apply from: "$DOC_VALIDATION"

dependencies {
compile project(":arrow-optics-mtl")
compile project(":arrow-optics")
compile "io.arrow-kt:arrow-generic:$VERSION_NAME"
compile "io.arrow-kt:arrow-aql:$VERSION_NAME"
compile "io.arrow-kt:arrow-syntax:$VERSION_NAME"
Expand Down
33 changes: 0 additions & 33 deletions arrow-docs/docs/getter/README.md
Expand Up @@ -42,39 +42,6 @@ val headGetter: Getter<NonEmptyList<String>, String> = NonEmptyList.head<String>
val tupleGetter: Getter<Tuple2<String, Int>, String> = Tuple2.first<String, Int>().asGetter()
```

`Getter` also has some convenience methods to make working with [Reader]({{ '/arrow/mtl/reader/' | relative_url }}) easier.

```kotlin:ank
import arrow.optics.mtl.*
import arrow.mtl.*

val reader: Reader<NonEmptyList<String>, String> = NonEmptyList.head<String>().asGetter().ask()

reader
.map(String::toUpperCase)
.runId(NonEmptyList("Hello", "World", "Viewed", "With", "Optics"))
```

```kotlin:ank
NonEmptyList.head<String>().asGetter().asks(String::decapitalize)
.runId(NonEmptyList("Hello", "World", "Viewed", "With", "Optics"))
```

There are also some convenience methods to make working with [State]({{ '/apidocs/arrow-mtl-data/arrow.mtl/-state.html' | relative_url }}) easier.

```kotlin:ank
import arrow.optics.mtl.*
import arrow.mtl.*

val inspectHealth = healthGetter.extract()
inspectHealth.run(player)
```

```kotlin:ank
val takeMedpack = healthGetter.extractMap { it + 25 }
takeMedpack.run(player)
```

## Composition

Unlike a regular `get` function, a `Getter` composes. Similar to a `Lens`, we can compose `Getter`s to create telescopes and zoom into nested structures.
Expand Down
38 changes: 0 additions & 38 deletions arrow-docs/docs/lens/README.md
Expand Up @@ -58,44 +58,6 @@ val liftF: (Player) -> OptionOf<Player> = playerLens.liftF(Option.functor()) { (
liftF(player)
```

There are also some convenience methods to make working with [Reader]({{ '/arrow/mtl/reader/' | relative_url }}) easier.

```kotlin:ank
import arrow.optics.mtl.*
import arrow.mtl.*

val reader: Reader<Player, Int> = playerLens.ask()

reader
.map(Int::inc)
.runId(Player(50))
```

```kotlin:ank
playerLens.asks(Int::inc)
.runId(Player(50))
```

There are also some convenience methods to make working with [State]({{ '/apidocs/arrow-mtl-data/arrow.mtl/-state.html' | relative_url }}) easier.
This can make working with nested structures in stateful computations significantly more elegant.

```kotlin:ank
import arrow.mtl.*

val inspectHealth = playerLens.extract()
inspectHealth.run(player)
```

```kotlin:ank
val takeDamage = playerLens.update { it - 15 }
takeDamage.run(player)
```

```kotlin:ank
val restoreHealth = playerLens.assign(100)
restoreHealth.run(player)
```

### Composition

By composing lenses, we can create a telescope that allows us to focus in on nested structures.
Expand Down
15 changes: 0 additions & 15 deletions arrow-docs/docs/setter/README.md
Expand Up @@ -52,21 +52,6 @@ val lift = playerSetter.lift(increment)
lift(Player(75))
```

There are also some convenience methods to make working with [State]({{ '/arrow/mtl/state/' | relative_url }}) easier.
This can make working with nested structures in stateful computations significantly more elegant.

```kotlin:ank
import arrow.optics.mtl.*

val takeDamage = playerSetter.update_ { it - 15 }
takeDamage.run(Player(75))
```

```kotlin:ank
val restoreHealth = playerSetter.assign_(100)
restoreHealth.run(Player(75))
```

## Composition

Unlike a regular `set` function, a `Setter` composes. Similar to a [`Lens`]({{'/optics/lens' | relative_url }}), we can compose `Setter`s to focus into nested structures and set or modify a value.
Expand Down
20 changes: 0 additions & 20 deletions arrow-docs/docs/traversal/README.md
Expand Up @@ -59,26 +59,6 @@ Tuple2.traversal<String>().combineAll(String.monoid(), "Hello, " toT "World!")
Tuple10.traversal<Int>().getAll(Tuple10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
```

There are also some convenience methods to make working with [State]({{ '/apidocs/arrow-mtl-data/arrow.mtl/-state.html' | relative_url }}) easier.
This can make working with nested structures in stateful computations significantly more elegant.

```kotlin:ank
import arrow.optics.mtl.*

data class Enemy(val health: Int)
val battlefield = listOf(Enemy(70), Enemy(80), Enemy(65)).k()

val dropBomb = ListK.traversal<Enemy>().update { it.copy(health = it.health - 50) }

dropBomb.run(battlefield)
```

```kotlin:ank
val finishingMove = ListK.traversal<Enemy>().assign(Enemy(0))

finishingMove.run(battlefield)
```

## Composition

Composing `Traversal` can be used for accessing and modifying foci in nested structures.
Expand Down
8 changes: 8 additions & 0 deletions arrow-optics-mtl/build.gradle
Expand Up @@ -7,6 +7,14 @@ apply from: "$SUB_PROJECT"
apply from: "$DOC_CREATION"

dependencies {
compile "io.arrow-kt:arrow-core:$VERSION_NAME"
compile "io.arrow-kt:arrow-mtl-data:$VERSION_NAME"
compile project(":arrow-optics")

testCompile project(":arrow-optics-test")

testCompile "junit:junit:$JUNIT_VERSION"

testRuntime "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION"
testCompile "io.kotlintest:kotlintest-runner-junit5:$KOTLIN_TEST_VERSION", excludeArrow
}
40 changes: 40 additions & 0 deletions arrow-optics-mtl/docs/getter/README.md
@@ -0,0 +1,40 @@
---
layout: docs-optics
title: Getter
permalink: /optics/getter/
---

## Getter

`Getter` also has some convenience methods to make working with [Reader]({{ '/arrow/mtl/reader/' | relative_url }}) easier.

```kotlin:ank
import arrow.optics.mtl.*
import arrow.mtl.*

val reader: Reader<NonEmptyList<String>, String> = NonEmptyList.head<String>().asGetter().ask()

reader
.map(String::toUpperCase)
.runId(NonEmptyList("Hello", "World", "Viewed", "With", "Optics"))
```

```kotlin:ank
NonEmptyList.head<String>().asGetter().asks(String::decapitalize)
.runId(NonEmptyList("Hello", "World", "Viewed", "With", "Optics"))
```

There are also some convenience methods to make working with [State]({{ '/apidocs/arrow-mtl-data/arrow.mtl/-state.html' | relative_url }}) easier.

```kotlin:ank
import arrow.optics.mtl.*
import arrow.mtl.*

val inspectHealth = healthGetter.extract()
inspectHealth.run(player)
```

```kotlin:ank
val takeMedpack = healthGetter.extractMap { it + 25 }
takeMedpack.run(player)
```
45 changes: 45 additions & 0 deletions arrow-optics-mtl/docs/lens/README.md
@@ -0,0 +1,45 @@
---
layout: docs-optics
title: Lens
permalink: /optics/lens/
---

## Lens

There are also some convenience methods to make working with [Reader]({{ '/arrow/mtl/reader/' | relative_url }}) easier.

```kotlin:ank
import arrow.optics.mtl.*
import arrow.mtl.*

val reader: Reader<Player, Int> = playerLens.ask()

reader
.map(Int::inc)
.runId(Player(50))
```

```kotlin:ank
playerLens.asks(Int::inc)
.runId(Player(50))
```

There are also some convenience methods to make working with [State]({{ '/apidocs/arrow-mtl-data/arrow.mtl/-state.html' | relative_url }}) easier.
This can make working with nested structures in stateful computations significantly more elegant.

```kotlin:ank
import arrow.mtl.*

val inspectHealth = playerLens.extract()
inspectHealth.run(player)
```

```kotlin:ank
val takeDamage = playerLens.update { it - 15 }
takeDamage.run(player)
```

```kotlin:ank
val restoreHealth = playerLens.assign(100)
restoreHealth.run(player)
```
22 changes: 22 additions & 0 deletions arrow-optics-mtl/docs/setter/README.md
@@ -0,0 +1,22 @@
---
layout: docs-optics
title: Setter
permalink: /optics/setter/
---

## Setter

There are also some convenience methods to make working with [State]({{ '/arrow/mtl/state/' | relative_url }}) easier.
This can make working with nested structures in stateful computations significantly more elegant.

```kotlin:ank
import arrow.optics.mtl.*

val takeDamage = playerSetter.update_ { it - 15 }
takeDamage.run(Player(75))
```

```kotlin:ank
val restoreHealth = playerSetter.assign_(100)
restoreHealth.run(Player(75))
```
27 changes: 27 additions & 0 deletions arrow-optics-mtl/docs/traversal/README.md
@@ -0,0 +1,27 @@
---
layout: docs-optics
title: Traversal
permalink: /optics/traversal/
---

## Traversal

There are also some convenience methods to make working with [State]({{ '/apidocs/arrow-mtl-data/arrow.mtl/-state.html' | relative_url }}) easier.
This can make working with nested structures in stateful computations significantly more elegant.

```kotlin:ank
import arrow.optics.mtl.*

data class Enemy(val health: Int)
val battlefield = listOf(Enemy(70), Enemy(80), Enemy(65)).k()

val dropBomb = ListK.traversal<Enemy>().update { it.copy(health = it.health - 50) }

dropBomb.run(battlefield)
```

```kotlin:ank
val finishingMove = ListK.traversal<Enemy>().assign(Enemy(0))

finishingMove.run(battlefield)
```
62 changes: 62 additions & 0 deletions arrow-optics-mtl/src/test/kotlin/arrow/optics/GetterTest.kt
@@ -0,0 +1,62 @@
package arrow.optics

import arrow.core.test.UnitSpec
import arrow.core.test.generators.functionAToB
import arrow.core.toT
import arrow.mtl.State
import arrow.mtl.map
import arrow.mtl.run
import arrow.mtl.runId
import arrow.optics.mtl.ask
import arrow.optics.mtl.asks
import arrow.optics.mtl.extract
import arrow.optics.mtl.extractMap
import arrow.optics.mtl.toReader
import arrow.optics.mtl.toState
import io.kotlintest.properties.Gen
import io.kotlintest.properties.forAll

class GetterTest : UnitSpec() {

init {

"Asking for the focus in a Reader" {
forAll(genToken) { token: Token ->
tokenGetter.ask().runId(token) == token.value
}
}

"toReader is an alias for ask" {
forAll(genToken) { token: Token ->
tokenGetter.ask().runId(token) == tokenLens.toReader().runId(token)
}
}

"Asks with f is the same as applying f to the focus of the lens" {
forAll(genToken, Gen.functionAToB<String, String>(Gen.string())) { token, f ->
tokenGetter.asks(f).runId(token) == f(token.value)
}
}

"Extract should extract the focus from the state" {
forAll(genToken) { generatedToken ->
tokenGetter.extract().run(generatedToken) ==
State { token: Token ->
token toT tokenGetter.get(token)
}.run(generatedToken)
}
}

"toState should be an alias to extract" {
forAll(genToken) { token ->
tokenGetter.toState().run(token) == tokenGetter.extract().run(token)
}
}

"extractMap with f should be same as extract and map" {
forAll(genToken, Gen.functionAToB<String, String>(Gen.string())) { token, f ->
tokenGetter.extractMap(f).run(token) == tokenGetter.extract().map(f).run(token)
}
}
}
}