Flowbius provides interoperability extensions for using Kotlin Flows with Mobius

Overview

Flowbius

Atlassian license PRs Welcome

Flowbius provides interoperability extensions for using Kotlin Flows with Mobius. They allow conversion from Flows to Mobius types and vice versa, as well as utilities to setup Mobius loops using Flows.

Flowbius is analogous to what mobius-rx provides for RxJava/Mobius interoperability.

Usage

Flowbius provides converters from Flow types to Mobius types:

// Flow -> EventSource
val eventSource = flowOf(1, 2, 3).asEventSource()

// EventSource -> Flow
val flow = eventSource.asFlow()

// FlowTransformer -> Connectable
val connectable = { source: Flow<String> -> source.map { it.length } }.asConnectable()

// Apply a Connectable to a Flow as a flatMap which merges emissions
val transformedFlow = flow.flatMapMerge(connectable)

You can also create a Mobius loop with Flow-based subtype effect handler:

val loop = FlowMobius.loop<Model, Event, Effect>(
  update = UpdateLogic(),
  effectHandler = subtypeEffectHandler {
    addConsumer(::handleEffects)
    addFunction(::effectToEvents)
  }
).startFrom(Model())

Installation

You can retrieve Flowbius from Maven Central.

implementation 'com.trello.flowbius:flowbius:0.1.0'

Tests

$ ./gradlew tests

Contributions

Contributions to Flowbius are welcome! Please see CONTRIBUTING.md for details.

License

Copyright (c) 2022 Atlassian and others. Apache 2.0 licensed, see LICENSE file.


With ❤️ from Atlassian

You might also like...
This project provides declarative camunda delegates for Spring based application

camunda-delegator-lib Features Declarative style for delegate code Generated delegates documentation and templates for camunda modeler(this feature is

Cago provides you way to do complex calculations on your device.

Cago Do your calculations easier. Cago provides you way to do complex calculations on your device. You can build functions that fit your goals by your

This prototype app provides a list of events to be held under an organization (school, college, club, etc.) and the users can manually set event reminders at their scheduled time so that they do not miss an event.

E-CELL NITS Sample App This prototype app provides a list of events to be held under E-Cell NIT Silchar (for example, Srijan 2.0) and the users can ma

Spring-graphql-getting-started - Spring for GraphQL provides support for Spring applications built on GraphQL Java

Getting Started with GraphQL and Spring Boot Spring for GraphQL provides support

🧮 Provides simple and advanced mathematical functions in a beautifully designed UI.
🧮 Provides simple and advanced mathematical functions in a beautifully designed UI.

Calculator 🧮 Android App 🔗 Download the App 🤔 What is this App ✍️ This will basically provide simple and advanced mathematical functions in a beaut

This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin.
This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin.

Lego 4 Rent This is a sample app to demonstrate the power of using EventSourced models and the ease with which these can be modelled using Kotlin. To

A complete Kotlin application built to demonstrate the use of Modern development tools with best practices implementation using multi-module architecture developed using SOLID principles
A complete Kotlin application built to demonstrate the use of Modern development tools with best practices implementation using multi-module architecture developed using SOLID principles

This repository serves as template and demo for building android applications for scale. It is suited for large teams where individuals can work independently on feature wise and layer wise reducing the dependency on each other.

Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP)

Mockative Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP). Installation Mockative uses KSP to generate

Screencast using Minecraft blocks using Minestom
Screencast using Minecraft blocks using Minestom

BlockScreen 🖥️ Usage Note: This can only be used locally, servers generally don't have capturable screens First, download the latest jar, then to sta

Comments
  • Can't run project on Apple M1 Machines when Flowbius dependency is added to a kotlin library module

    Can't run project on Apple M1 Machines when Flowbius dependency is added to a kotlin library module

    Summary

    Gradle Sync fails on Machines with Apple M1 Chipset when Flowbius dependency is added to the kotlin library module of my project. The project runs fine on Intel machines though.

    Dependency

    implementation 'com.trello.flowbius:flowbius:0.1.0'

    Description

    I'm trying to add flowbius to a kotlin library module of my project and I get the following error when I try to run the project on M1 machines:

    Execution failed for task ':core:compileKotlin'.
    > Error while evaluating property 'filteredArgumentsMap' of task ':core:compileKotlin'
       > Could not resolve all files for configuration ':core:compileClasspath'.
          > Could not resolve com.trello.flowbius:flowbius:0.1.0.
            Required by:
                project :core
             > No matching variant of com.trello.flowbius:flowbius:0.1.0 was found. The consumer was configured to find an API of a library compatible with Java 11, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
                 - Variant 'apiElements' capability com.trello.flowbius:flowbius:0.1.0 declares an API of a library, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
                     - Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11
                     - Other compatible attribute:
                         - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                 - Variant 'runtimeElements' capability com.trello.flowbius:flowbius:0.1.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
                     - Incompatible because this component declares a component compatible with Java 17 and the consumer needed a component compatible with Java 11
                     - Other compatible attribute:
                         - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
    

    This issue does not occur on Mac with Intel Chip. It is however resolved for M1 Chip Machine as well if I change my module's targetCompatibility to JavaVersion.VERSION_17 or when I change this module to to an android library.

    Project Configuration

    Gradle file of module in which I'm trying to add Flowbius:

    plugins {
        id 'org.jetbrains.kotlin.jvm'
    }
    
    dependencies {
        api "com.spotify.mobius:mobius-core:1.5.9"
        implementation 'com.trello.flowbius:flowbius:0.1.0'
    
        testImplementation "com.spotify.mobius:mobius-test:1.5.9"
        testImplementation "org.junit.jupiter:junit-jupiter-engine:5.8.2"
        testImplementation "org.junit.jupiter:junit-jupiter-params:5.8.2"
        testImplementation "com.google.truth:truth:1.1.3"
    }
    
    java {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    
    test {
        useJUnitPlatform()
    }
    

    Project's Root Gradle

    plugins {
        id 'com.android.application' version '7.2.2' apply false
        id 'com.android.library' version '7.2.2' apply false
        id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
        id 'org.jetbrains.kotlin.jvm' version '1.7.10' apply false
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    Environment

    Laptop: M1 Pro chip MBP with Mac OS Monterey 12.6.

    Android Studio: Android Studio Dolphin | 2021.3.1

    java --version: openjdk 11.0.15 2022-04-19 LTS OpenJDK Runtime Environment Zulu11.56+19-CA (build 11.0.15+10-LTS) OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

    opened by karanjhinga 1
  • Fix an issue where the effect flow wasn't shared.

    Fix an issue where the effect flow wasn't shared.

    Moved our internal channel to a shareflow with replay of 1 to handle the situation where the initial event gets missed in a rare race condition due to nested unconfined dispatchers.

    opened by bparent-atl 1
Owner
Atlassian Labs
Atlassian Labs
Clean MVVM with eliminating the usage of context from view models by introducing hilt for DI and sealed classes for displaying Errors in views using shared flows (one time event), and Stateflow for data

Clean ViewModel with Sealed Classes Following are the purposes of this repo Showing how you can remove the need of context in ViewModels. I. By using

Kashif Mehmood 22 Oct 26, 2022
FlowExt is a Kotlin Multiplatform library, that provides many operators and extensions to Kotlin Coroutines Flow

FlowExt | Kotlinx Coroutines Flow Extensions | Kotlinx Coroutines Flow Extensions. Extensions to the Kotlin Flow library | kotlin-flow-extensions | Coroutines Flow Extensions | Kotlin Flow extensions | kotlin flow extensions | Flow extensions

Petrus Nguyễn Thái Học 151 Jan 1, 2023
Set of extensions for Kotlin that provides Discrete math functionalities

DiscreteMathToolkit Set of extensions for Kotlin that provides Discrete Math functionalities as an Kotlin extension functions. To stay current with ne

Marcin Moskała 177 Dec 15, 2022
Kotlin extensions, BindingAdapters, Composable functions for Android CameraX

Setup dependencies { implementation "com.github.skgmn:cameraxx:0.6.0" } Features CameraXX provides extensions methods for CameraX to use functions

null 12 Aug 9, 2022
Various Ktor extensions and plugins.

Ktor Plugins Collection of useful Ktor plugins. All plugins are hosted on Maven central and have same version that should be similar to the latest ver

Lukas Forst 25 Nov 24, 2022
Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any type of design pattern

What is Kotlin Extension Function ? Kotlin extension function provides a facility to "add" methods to class without inheriting a class or using any ty

mohsen 21 Dec 3, 2022
Provides Ktor Server libs for building awesome Kotlin plugins which needs to provide builtin HTTP servers

Ktor Plugin Provides Ktor Server libs for building awesome Kotlin plugins which needs to provide builtin HTTP servers. Requires: https://github.com/Po

null 0 Nov 13, 2021
Kotter - aims to be a relatively thin, declarative, Kotlin-idiomatic API that provides useful functionality for writing delightful console applications.

Kotter (a KOTlin TERminal library) aims to be a relatively thin, declarative, Kotlin-idiomatic API that provides useful functionality for writing delightful console applications.

Varabyte 348 Dec 21, 2022
Andorid app which provides a bunch of useful Linux commands.

Linux Command Library for Android The app currently has 3203 manual pages, 1351 one-line scripts and a bunch of general terminal tips. It works 100% o

Simon Schubert 271 Dec 31, 2022
🔥The Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.

??The Android Startup library provides a straightforward, performant way to initialize components at the application startup. Both library developers and app developers can use Android Startup to streamline startup sequences and explicitly set the order of initialization.

Rouse 1.3k Dec 30, 2022