Attila Domokos
12/18/2019, 11:21 PMSome
values?Jannis
12/18/2019, 11:26 PMOption<A>.toList(): List<A>
. For a list of Some
values it depends, do you want behaviour like catMaybe
(http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Maybe.html#v:catMaybes) or do you want to short-circuit and return Nothing
when you encounter a Nothing
?Attila Domokos
12/19/2019, 1:45 AMcatMaybe :: [Maybe a] -> [a]
. Do we have a function in Arrow that does that? The team I work with found filterMap
, I wonder if that's what we should use.pakoito
12/19/2019, 3:21 AMAttila Domokos
12/19/2019, 3:23 AMcatSome
or something along that line? I would have never thought to use filterMap
, besides, this looks a bit awkward: filterMap { it }
.pakoito
12/19/2019, 4:12 AMpakoito
12/19/2019, 4:12 AMraulraja
12/19/2019, 11:48 AMcatSome
as an alias for filterMap
+ identity
is legit because it’s understood that filterMap short circuits on None. @pakoito this is similar to the traverse and sequence case.raulraja
12/19/2019, 11:49 AMtraverse(identity)
why do we need sequence
, it’s just a convenience for most users IMOpakoito
12/19/2019, 12:15 PMAttila Domokos
12/19/2019, 2:10 PMI did not know that. This is in the arrow docs:+filterMap
is legit because it’s understood that filterMap short circuits on None.identity
filterMap fun <B> filterMap(f: (A) -> Option<B>): Option<B>Should I add a bit more context to the docs here? https://arrow-kt.io/docs/apidocs/arrow-core-data/arrow.core/-option/ I was also thinking about having a function like
toValues
that could be used in an abstract way for Some
and Either
as well. Maybe that would help others finding this functionality.pakoito
12/19/2019, 2:14 PMcoflatMap
, we were actually checking the implementation with @Jannis yesterday 😄Jannis
12/19/2019, 2:15 PMtraverse
shorts on None
filterMap
completes, but removes all None
cases.Attila Domokos
12/19/2019, 2:15 PMfun <B> filterMap(f: (A) -> Option<B>): Option<B>
Attila Domokos
12/19/2019, 2:16 PMJannis
12/19/2019, 2:16 PMAttila Domokos
12/19/2019, 2:16 PM[Maybe a] -> [a]
is just so much more descriptive.Attila Domokos
12/19/2019, 2:17 PMFrom my understanding short-circuit means it aborts the outer function and immediatly returns.
Jannis
12/19/2019, 2:19 PMfun <A, B> Kind<F, A>.filterMap(f: (A) -> Option<B>): Kind<F, B>
is on FunctorFilter
which most collections that we support implement. We also have fun <A> Kind<F, Option<A>>.flattenOption(): Kind<F, A> = filterMap(::identity)
which for lists has the signature fun <A> Kind<ForListK, Option<A>>.flattenOption(): Kind<ForListK, A>
which is equal to fun <A> List<Option<A>>.flattenOption(): List<A>
. So we already have this 🙂Jannis
12/19/2019, 2:20 PMAttila Domokos
12/19/2019, 2:20 PMAttila Domokos
12/19/2019, 2:21 PMForListK
is definitely telling. 👍Jannis
12/19/2019, 2:21 PMFunctorFilter
does not have that much exposure on the docs (if any)pakoito
12/19/2019, 2:21 PMpakoito
12/19/2019, 2:21 PMpakoito
12/19/2019, 2:22 PMAttila Domokos
12/19/2019, 2:22 PMpakoito
12/19/2019, 2:22 PMAttila Domokos
12/19/2019, 2:23 PMHoogle
definitely helps.pakoito
12/19/2019, 2:23 PMpakoito
12/19/2019, 2:23 PMAttila Domokos
12/19/2019, 2:24 PMJannis
12/19/2019, 2:27 PMraulraja
12/19/2019, 2:27 PMraulraja
12/19/2019, 2:27 PMraulraja
12/19/2019, 2:28 PMraulraja
12/19/2019, 2:28 PMraulraja
12/19/2019, 2:29 PMraulraja
12/19/2019, 2:29 PMAttila Domokos
12/19/2019, 2:30 PM[Maybe a] -> [a]
is super sweet. KindOf(ListOfK of (ListtOfK of something)) -> KindOf(ListOfK of somethingElse)
is a lot more work.Jannis
12/19/2019, 2:30 PMJannis
12/19/2019, 2:30 PMpakoito
12/19/2019, 2:31 PMwe need a use case section with ideasit's there 😄
Jannis
12/19/2019, 2:44 PMJannis
12/19/2019, 3:12 PMraulraja
12/19/2019, 4:20 PMraulraja
12/19/2019, 4:20 PMraulraja
12/19/2019, 4:21 PMraulraja
12/19/2019, 4:22 PMraulraja
12/19/2019, 4:23 PMraulraja
12/19/2019, 4:23 PMJannis
12/19/2019, 5:11 PMraulraja
12/19/2019, 6:48 PM