Skip to content

Instantly share code, notes, and snippets.

@thosakwe
Created June 28, 2021 21:03
Show Gist options
  • Save thosakwe/67ca2928a58d4da1ead3fb4b46603efc to your computer and use it in GitHub Desktop.
Save thosakwe/67ca2928a58d4da1ead3fb4b46603efc to your computer and use it in GitHub Desktop.
Dart monad [WIP]
abstract class Monad<T> {
abstract MonadInstance<U> bind<U>(FutureOr<Monad<U>> Function(T) f);
abstract MonadInstance<T> wrap(T value);
}
abstract class EitherMonad<L, R> extends Monad<Either<L, R>> {
static EitherMonad<L, Exception> wrapTryCatch<L>(FutureOr<L> Function() f);
abstract EitherMonad<U, R> bindLeft(FutureOr<U> Function(L) f);
abstract EitherMonad<L, U> bindRight(FutureOr<U> Function(R) f);
}
class IOMonad<T> extends EitherMonad<T, IOException> {
// final EitherMonad<T, IOException>
IOMonad();
}
main() async {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment