Skip to content
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

["Request"] Improve documentation for filtering within list #3314

Open
n3ziniuka5 opened this issue Dec 7, 2023 · 0 comments
Open

["Request"] Improve documentation for filtering within list #3314

n3ziniuka5 opened this issue Dec 7, 2023 · 0 comments

Comments

@n3ziniuka5
Copy link

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<Int>() 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<Int>() compose OptionalGetter.filter { it >= 0 } doesn't compile:

ype mismatch: inferred type is OptionalGetter<???, ???> /* = POptionalGetter<???, ???, ???> */ but PTraversal<in Int, out Int, out TypeVariable(C), in TypeVariable(D)> 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<B>, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant