monadic-jfx

Enrichment classes over JavaFX bindings to provide monadic operations in Scala.

License

License

Categories

Categories

Search Business Logic Libraries
GroupId

GroupId

com.elderresearch
ArtifactId

ArtifactId

monadic-jfx_2.11
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

monadic-jfx
Enrichment classes over JavaFX bindings to provide monadic operations in Scala.
Project URL

Project URL

http://github.com/ElderResearch/monadic-jfx
Project Organization

Project Organization

com.elderresearch
Source Code Management

Source Code Management

http://github.com/ElderResearch/monadic-jfx

Download monadic-jfx_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/com.elderresearch/monadic-jfx_2.11/ -->
<dependency>
    <groupId>com.elderresearch</groupId>
    <artifactId>monadic-jfx_2.11</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.elderresearch/monadic-jfx_2.11/
implementation 'com.elderresearch:monadic-jfx_2.11:0.1.1'
// https://jarcasting.com/artifacts/com.elderresearch/monadic-jfx_2.11/
implementation ("com.elderresearch:monadic-jfx_2.11:0.1.1")
'com.elderresearch:monadic-jfx_2.11:jar:0.1.1'
<dependency org="com.elderresearch" name="monadic-jfx_2.11" rev="0.1.1">
  <artifact name="monadic-jfx_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.elderresearch', module='monadic-jfx_2.11', version='0.1.1')
)
libraryDependencies += "com.elderresearch" % "monadic-jfx_2.11" % "0.1.1"
[com.elderresearch/monadic-jfx_2.11 "0.1.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.7
org.spire-math : cats-core_2.11 jar 0.2.0

test (3)

Group / Artifact Type Version
org.spire-math : cats-laws_2.11 jar 0.2.0
org.typelevel : discipline_2.11 jar 0.4
org.scalatest : scalatest_2.11 jar 3.0.0-M7

Project Modules

There are no modules declared in this project.

monadic-jfx

Build Status

Join the chat at https://gitter.im/ElderResearch/monadic-jfx

Enrichment classes over JavaFX bindings to provide monadic operations in Scala.

Implemented using the functional programming type-classes from non/cats.

Getting Started

monadic-jfx requires Scala 2.11 and Java 8 build >= 40.

The SBT dependency is:

libraryDependencies += "com.elderresearch" %% "monadic-jfx" % "0.1.1"

In your code, add:

import eri.viz.gui.jfx.monadic._

And then you can create derived bindings with map and flatMap from a JavaFX property/observable value:

import javafx.beans.property.SimpleObjectProperty
import javafx.scene.control.Label
import eri.viz.gui.jfx.monadic._

// Create a simple data model with property hierarchy
class Player {
  val name = new SimpleObjectProperty[String]("Player 1")
  val stats = new SimpleObjectProperty[PlayerStats](new PlayerStats)
}

class PlayerStats {
  val highScore = new SimpleObjectProperty[Integer](0)
  val losses = new SimpleObjectProperty[Integer](0)
}

// Root property
val currentPlayer = new SimpleObjectProperty[Player]

// Some controls with properties to bind
val nameLabel = new Label
val highScoreLabel = new Label

// Name is a simple first order property
nameLabel.textProperty().bind(
  currentPlayer.flatMap(_.name)
)

// High Score is a second order property with a transformation
highScoreLabel.textProperty().bind(
  currentPlayer
    .flatMap(_.stats)
    .flatMap(_.highScore)
    .map(s  s">> $s <<")
)

// Same thing, but using a for comprehension
highScoreLabel.textProperty().bind(
  for {
    p  currentPlayer
    s  p.stats
    hs  s.highScore
  } yield s">> $hs <<"
)

// Test property binding
assert(nameLabel.getText == null)
assert(highScoreLabel.getText == null)

currentPlayer.set(new Player)

assert(nameLabel.getText == "Player 1")
assert(highScoreLabel.getText == ">> 0 <<")

currentPlayer.get.stats.get.highScore.set(1000000)
assert(highScoreLabel.getText == ">> 1000000 <<")
com.elderresearch

Elder Research, Inc.

Data Science • Machine Learning • AI

Versions

Version
0.1.1
0.1.0