Skip to main content

juxta 1.0.0 copy "juxta: ^1.0.0" to clipboard
juxta: ^1.0.0 copied to clipboard

A lightweight Dart library for expression-oriented programming.

juxta #

A lightweight Dart library for expression-oriented programming. Inspired from my time with Clojure.

juxta provides small, composable utilities for writing cleaner conditional logic, reusable predicates, and fluent value transformations. It is designed for developers who prefer concise, readable building blocks over repeated control-flow boilerplate.

Highlights #

  • Express multi-branch logic as values
  • Compose predicates into reusable rules
  • Transform values fluently with piping helpers
  • Keep nullable flows readable and safe
  • Add side effects without breaking expression chains

Features #

Conditional helpers #

Write branching logic in a compact, expression-friendly style.

  • cond
  • condp
  • when
  • whenNot

Predicate composition #

Build reusable boolean logic from small functions.

  • Predicate<T>
  • and
  • or
  • not
  • complement
  • everyPredicate
  • somePredicate

Threading and piping extensions #

Transform values inline without introducing temporary variables.

  • pipe
  • tap
  • somePipe
  • someTap
  • apply

Why juxta? #

Dart already gives you solid language features. juxta aims to complement them with a focused set of helpers for code that is:

  • more declarative
  • easier to compose
  • simpler to reuse
  • pleasant to read in pipelines

It is especially useful when you want business rules and transformations to read like expressions instead of scaffolding.

Installation #

Add the package to your pubspec.yaml:

dependencies:
  juxta: ^1.0.0

Then fetch dependencies:

dart pub get

Import #

import 'package:juxta/juxta.dart';

Usage #

Conditional expressions #

import 'package:juxta/juxta.dart';

void main() {
  final score = 82;

  final grade = cond<String>(
    [
      (score >= 90, () => 'A'),
      (score >= 80, () => 'B'),
      (score >= 70, () => 'C'),
    ],
    orElse: () => 'D',
  );

  print(grade); // B
}

Predicate composition #

import 'package:juxta/juxta.dart';

void main() {
  final isPositive = (int value) => value > 0;
  final isEven = (int value) => value.isEven;

  final isPositiveAndEven = and<int>(isPositive, isEven);

  print(isPositiveAndEven(4)); // true
  print(isPositiveAndEven(3)); // false
  print(isPositiveAndEven(-2)); // false
}

Fluent transformations #

import 'package:juxta/juxta.dart';

void main() {
  final result = '  dart  '
      .pipe((value) => value.trim())
      .tap((value) => print('Trimmed: $value'))
      .pipe((value) => value.toUpperCase());

  print(result); // DART
}

Nullable-friendly pipelines #

import 'package:juxta/juxta.dart';

void main() {
  final greeting = 'dart'
      .somePipe((value) => value.toUpperCase())
      .somePipe((value) => 'Hello, $value');

  final missing = (null as String?)
      .somePipe((value) => value.toUpperCase());

  print(greeting); // Hello, DART
  print(missing); // null
}

API overview #

Conditionals #

Use these helpers when you want conditional logic to stay expression-based:

  • cond returns the first matching clause result
  • condp matches using custom logic
  • when runs a branch only when a condition is true
  • whenNot runs a branch only when a condition is false

Predicates #

Use these helpers to combine boolean rules cleanly:

  • and and or combine predicates
  • not and complement invert predicates
  • everyPredicate requires all predicates to match
  • somePredicate requires at least one predicate to match

Extensions #

Use these helpers to keep transformations fluent:

  • pipe transforms a value
  • tap performs a side effect and returns the original value
  • somePipe transforms nullable values safely
  • someTap performs side effects on nullable values safely
  • apply performs a side effect and returns the original value

Example #

import 'package:juxta/juxta.dart';

void main() {
  final isValidName = everyPredicate<String>([
    (value) => value.isNotEmpty,
    (value) => value.length >= 3,
    (value) => value.startsWith('j'),
  ]);

  final label = cond<String>(
    [
      (isValidName('juxta'), () => 'valid'),
    ],
    orElse: () => 'invalid',
  );

  final output = 'juxta'
      .pipe((value) => value.toUpperCase())
      .apply((value) => print('Computed: $value'));

  print(label); // valid
  print(output); // JUXTA
}
0
likes
150
points
9
downloads

Documentation

API reference

Publisher

verified publisheraxrs.dev

Weekly Downloads

A lightweight Dart library for expression-oriented programming.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on juxta