Skip to content

Latest commit

 

History

History
45 lines (28 loc) · 2.14 KB

README.md

File metadata and controls

45 lines (28 loc) · 2.14 KB

Android Comonadic UI

An Android application implemented in a declarative way bringing some concepts from Comonadic Declarative UIs using Λrrow.

What is a Comonad?

Comonads are the dual of Monads.

A Comonad represents a Space of points. We can consider a UI as a Space of states. So we can build a UI with a Comonad as it is a Space of all possible points, and user actions are movements inside this Space. Source

For example, Store is a comonadic datatype which holds a state and a render function (lambda) for giving a visual representation of its state. We can extract() the Comonad which means giving a representation of the current point in the Space. We can also move(newState) the Comonad inside the Space.

class MainActivity : Activity() {

    var greetingComponent: Store<String, Unit> by observable(Store(initialState = "John Doe") { state ->
        user_name_textview.text = state
    }) { _, _, new -> new.extract() }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        greetingComponent.extract()                                 // The textview should show "John Doe"
        greetingComponent = greetingComponent.move("A new name")    // The textview should show "A new name"
      }
}

This declarative approach is similar to other libraries and languages for frontend applications like React, Elm, Halogen, etc.

🏅 The Future is Comonadic 🏅

Scope

This app is a classical TODOs manager example. The core features are:

  • Showing a list of TODOs. If there are no tasks then an empty case should be shown.
  • Marking a TODO as completed. It's title should be struck through.
  • Deleting a TODO.
  • Creating new TODOs.

In the future we will add more features for showing how we can interact with the Android framework with a declarative approach.