Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fardhanardhi/063f7fed6d07c128a62bc2babcbb351f to your computer and use it in GitHub Desktop.
Save fardhanardhi/063f7fed6d07c128a62bc2babcbb351f to your computer and use it in GitHub Desktop.
dartz applicatives curried addition (.ap)

Dart Dartz Functional Programming Applicative Currying

Dartz applicatives curried addition (.ap)

The practical example of applicative and curry function using dartz

Warning

This snippet uses dartz package, so make sure you have already imported it.

import 'package:dartz/dartz.dart';

Code

void main() {
  final curried = (String x) => (double y) => (int z) {
        return x + y.toString() + z.toString();
      };

  final a = some('x').map(curried);
  final b = some(5.0).ap(a);
  final c = some(-5).ap(b);

  print(c);
}

Result

Some(x5.0-5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment