Does Kotlin support monadic comprehension?

Winter Young

Like LINQ in C#, for comprehension in Scala, anything similar in Kotlin? If not supported, is it planned?

fdelsert

There is no special keyword (do/for) and so no direct translation to nested flatMap (desugaring) like in other languages.

But monadic comprehension can be implemented with coroutines.

From Arrow documentation : https://arrow-kt.io/docs/patterns/monad_comprehensions/#comprehensions-over-coroutines

Comprehensions over coroutines

This feature is known with multiple names: async/await, coroutines, do notation, for comprehensions…each version contains certain unique points but all derive from the same principles. In Kotlin, coroutines (introduced in version 1.1 of the language) make the compiler capable of rewriting seemingly synchronous code into asynchronous sequences. Arrow uses this capability of the compiler to bring you coroutines-like notation to all instances of the Monad typeclass.

This means that comprehensions are available for Option, Try, List, Reader, Observable, Flux or IO all the same.

For coroutines, see also "Deep dive into Coroutines on JVM @ KotlinConf 2017" : https://www.slideshare.net/elizarov/deep-dive-into-coroutines-on-jvm-kotlinconf-2017?next_slideshow=1

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

What does it mean if macros in a Lisp are monadic?

分類Dev

How does this dictionary comprehension differ from this "for" loop?

分類Dev

Does Swift support reflection?

分類Dev

what is difference between monadic collection, monadic type and monadic operation?

分類Dev

Does Ubuntu support USB 3.0?

分類Dev

Does Landscape support Ubuntu derivatives?

分類Dev

Does Java 8 support interpolation

分類Dev

What formats does the MediaElement support?

分類Dev

Does ReasonML support async/await?

分類Dev

Does python support to import package

分類Dev

MongoError: server does not support collation

分類Dev

Does Kusto not support regex lookarounds?

分類Dev

Does Azure APIM support GraphQL?

分類Dev

Does keycloak support mongodb as a database?

分類Dev

Does SQLite support character range with [ ]?

分類Dev

Does Solr support search operators?

分類Dev

Does MariaDB support nested transactions?

分類Dev

Does cocoapods support MacOSX programming?

分類Dev

Does Android support weak symbols?

分類Dev

Does Firefox support folder upload?

分類Dev

Does LVM support unwritten extents?

分類Dev

Does the RSS protocol support categories?

分類Dev

Does Redis support file caching?

分類Dev

Does Ubuntu support Windows applications?

分類Dev

Why does this list comprehension throw an out of range error

分類Dev

Why does this list comprehension only work on one list?

分類Dev

Something more to "monadic application"?

分類Dev

What hardware does Ubuntu Touch support?

分類Dev

invalid operation: (type interface {} does not support indexing)