thanh
11/11/2021, 4:13 PMpublic fun <A> listPredicate(p: (A) -> Boolean): Optional<List<A>, A> = Optional(
getOption = { it.firstOrNull(p).toOption() },
set = { list, newHead ->
val index = list.indexOfFirst(p)
if (index != -1) list.take(index) + newHead + list.drop(index + 1) else list
}
)simon.vergauwen
11/11/2021, 5:13 PMsimon.vergauwen
11/11/2021, 5:14 PMsimon.vergauwen
11/11/2021, 5:14 PMthanh
11/11/2021, 6:24 PMFilterIndex I want to filter with the value of the item in the list, not with the index. Maybe I missed something here?simon.vergauwen
11/11/2021, 6:33 PMthanh
11/11/2021, 6:52 PMLens<List<A>, List<A>> which can get/set/modify all satisfied items.simon.vergauwen
11/11/2021, 7:04 PMthanh
11/11/2021, 7:41 PMthanh
11/12/2021, 5:55 PMoptics? Maybe I can do some research how Haskell Lens deals with this problem first.simon.vergauwen
11/12/2021, 5:59 PMFilterIndex they’re defined over indices of the list.simon.vergauwen
11/12/2021, 6:00 PMOptionalLaws from arrow-optics-test. Have you tried running those against this instance?thanh
11/12/2021, 6:08 PMLaws yet, but I can try to tests with the Laws tomorrow. I used it in a project and did some tests and it composes well with other optics functions.thanh
11/16/2021, 8:47 AMOptionalLaws and how to run the tests. Maybe I'll just create a PR and you can correct me there.simon.vergauwen
11/16/2021, 8:47 AMthanh
11/16/2021, 8:49 AMthanh
11/16/2021, 8:49 AMthanh
11/16/2021, 8:50 AMsimon.vergauwen
11/16/2021, 8:56 AMsimon.vergauwen
11/16/2021, 8:57 AMfiltered in Haskellthanh
11/16/2021, 9:05 AMoptics can definitely use some loves.