arrow-kt / arrow-kt/arrow

["Request"] Improve documentation for filtering within list

Open
#3,314 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
6.6k
Forks
472
Avg merge
3d 49m
Merged PRs (30d)
4

Description

What version are you currently using? 1.2.0

What would you like to see?

`OptionalGetter.filter` has the following javadoc:
```
/**
* [OptionalGetter] to itself if it satisfies the predicate.
*
* Select all the elements which satisfy the predicate.
*
* ```kotlin
* import arrow.optics.Traversal
* import arrow.optics.Optional
*
* val positiveNumbers = Traversal.list() compose OptionalGetter.filter { it >= 0 }
*
* positiveNumbers.getAll(listOf(1, 2, -3, 4, -5)) == listOf(1, 2, 4)
* ```
*/
```

The issue I am facing is that `Traversal.list() compose OptionalGetter.filter { it >= 0 }` doesn't compile:
```
ype mismatch: inferred type is OptionalGetter /* = POptionalGetter */ but PTraversal was expected
Type mismatch: inferred type is (???) -> Unit but (???) -> Boolean was expected
Type mismatch: inferred type is Unit but Boolean was expected
```

At the moment I am struggling to find examples on how to zoom into a particular element in the list. My use-case is a data class `A` with a property `b: List`, and given `A`, I want to make a change to `B.someProperty`, but only for a list element that satisfies some condition. Help would be appreciated.

Contributor guide

Open the contributing guide

Research direction

Read the OptionalGetter.filter Javadoc and surrounding optics documentation first; reproduce the shown Kotlin snippet to confirm the reported type errors. Update the filtering documentation with a compiling example that addresses selecting a matching list element for the stated A/B use case, then verify the example and its expected result.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.