Skip to content

Commit

Permalink
Doc for SetKW
Browse files Browse the repository at this point in the history
  • Loading branch information
itua committed Feb 2, 2018
1 parent 25ff3bf commit 664c9a6
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion arrow-docs/docs/docs/datatypes/setkw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,54 @@ permalink: /docs/datatypes/setkw/

## SetKW

TODO
SetKW(Kinded Wrapper) is a higher kinded wrapper around the the Set collection interface.

It can be created from the Kotlin Set type with a convient `k()` function.

```kotlin:ank
import arrow.*
import arrow.core.*
import arrow.data.*
setOf(1, 2, 5, 3, 2).k()
```

It can also be initialized with the following:

```kotlin:ank
SetKW(setOf(1, 2, 5, 3, 2))
```
or
```kotlin:ank
SetKW.pure(1)
```

given the following:
```kotlin:ank
val oldNumbers = setOf( -11, 1, 3, 5, 7, 9).k()
val evenNumbers = setOf(-2, 4, 6, 8, 10).k()
val integers = setOf(-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5).k()
```
SetKW derives the following typeclasses:

[`Semigroup`](/docs/typeclasses/semigroupk/):
```kotlin:ank
val uniqueNaturalNumbers_1 = oldNumbers.combineK(evenNumbers.combineK(integers))
uniqueNaturalNumbers_1
```
```kotlin:ank
val uniqueNaturalNumbers_2 = oldNumbers.combineK(evenNumbers).combineK(integers)
uniqueNaturalNumbers_2
```
[`Foldable`](/docs/typeclasses/foldable/):
```kotlin:ank
val sum_1 = uniqueNaturalNumbers_1.foldLeft(0){sum, number -> sum + (number * number)}
val sum_2 = uniqueNaturalNumbers_2.foldLeft(0){sum, number -> sum + (number * number)}
sum_1 == sum_2
```
[`Monoid`](/docs/typeclasses/monoidk/):
```kotlin:ank
val sum_3 = SetKW.monoid<Int>().combine(uniqueNaturalNumbers_1, SetKW.empty()).foldLeft(0){sum, number -> sum + (number * number)}
val sum_4 = SetKW.monoid<Int>().combine(SetKW.empty(), uniqueNaturalNumbers_1).foldLeft(0){sum, number -> sum + (number * number)}
sum_3 == sum_4
```

0 comments on commit 664c9a6

Please sign in to comment.