Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Updates for Dart 2.0 core library changes (wave 2.2) - step 1 (#41)
Browse files Browse the repository at this point in the history
* Updates for Dart 2.0 core library changes (wave 2.2) - step 1

* Make pubspec version a dev release
  • Loading branch information
leafpetersen authored and alexeieleusis committed Jan 31, 2018
1 parent e8e09e1 commit 7ad1906
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
40 changes: 31 additions & 9 deletions lib/src/instances/stream_monad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ class StreamMonad<T> extends Monad<T> implements Stream<T> {
return new StreamMonad(controller.stream);
}

@override
// TODO: Dart 2.0 requires this method to be implemented.
// See https://github.com/dart-lang/sdk/issues/31847 .
// ignore: override_on_non_overriding_method
Stream<T> cast<T>() {
throw new UnimplementedError("cast");
}

@override
// TODO: Dart 2.0 requires this method to be implemented.
// See https://github.com/dart-lang/sdk/issues/31847 .
// ignore: override_on_non_overriding_method
Stream<T> retype<T>() {
throw new UnimplementedError("retype");
}

/// Combines this and another to create an stream whose events are
/// calculated from the latest values of each stream.
StreamMonad<E> combineLatest<S, E>(
Expand Down Expand Up @@ -331,8 +347,10 @@ class StreamMonad<T> extends Monad<T> implements Stream<T> {
new StreamMonad(_stream.expand(convert));

@override
FutureMonad firstWhere(bool test(T element), {Object defaultValue()}) =>
new FutureMonad(_stream.firstWhere(test, defaultValue: defaultValue));
FutureMonad<T> firstWhere(bool test(T element),
{Object defaultValue(), T orElse()}) =>
new FutureMonad(
_stream.firstWhere(test, defaultValue: defaultValue ?? orElse));

@override
StreamMonad<S> flatMap<S>(Function1<T, StreamMonad<S>> f) {
Expand All @@ -355,10 +373,10 @@ class StreamMonad<T> extends Monad<T> implements Stream<T> {
// new events and notify source streams to close also.
void _close() {
sourceSubscription.cancel();
for(var subscription in subscriptions) {
for (var subscription in subscriptions) {
subscription.cancel();
}
if(!controller.isClosed) {
if (!controller.isClosed) {
controller.close();
}
}
Expand Down Expand Up @@ -390,6 +408,7 @@ class StreamMonad<T> extends Monad<T> implements Stream<T> {
}
controller.add(s);
}

// Count this subscription.
count++;
// We start listening as we get the data.
Expand All @@ -403,7 +422,8 @@ class StreamMonad<T> extends Monad<T> implements Stream<T> {

controller
..onListen = () {
sourceSubscription = _stream.listen(_onData, onError: _onError, onDone: _onDone);
sourceSubscription =
_stream.listen(_onData, onError: _onError, onDone: _onDone);
}
..onCancel = _close;
return new StreamMonad(controller.stream);
Expand All @@ -427,8 +447,10 @@ class StreamMonad<T> extends Monad<T> implements Stream<T> {
new FutureMonad(_stream.join(separator));

@override
FutureMonad lastWhere(bool test(T element), {Object defaultValue()}) =>
new FutureMonad(_stream.lastWhere(test, defaultValue: defaultValue));
FutureMonad<T> lastWhere(bool test(T element),
{Object defaultValue(), T orElse()}) =>
new FutureMonad(
_stream.lastWhere(test, defaultValue: defaultValue ?? orElse));

@override
StreamSubscription<T> listen(void onData(T event),
Expand Down Expand Up @@ -515,8 +537,8 @@ class StreamMonad<T> extends Monad<T> implements Stream<T> {
}

@override
FutureMonad<T> singleWhere(bool test(T element)) =>
new FutureMonad(_stream.singleWhere(test));
FutureMonad<T> singleWhere(bool test(T element), {T orElse()}) =>
new FutureMonad(_stream.singleWhere(test) ?? orElse());

@override
StreamMonad<T> skip(int count) => new StreamMonad(_stream.skip(count));
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: shuttlecock
description: An algebraic types library inspired by the course Category theory for programmers by Bartosz Milewski. https://www.youtube.com/playlist?list=PLbgaMIhjbmEnaH_LTkxLI7FMa2HsnawM_
version: 0.4.4
version: 0.4.5-dev
author: Alexei Eleusis Díaz Vera <alexei.eleusis@gmail.com>
homepage: https://github.com/alexeieleusis/shuttlecock

environment:
sdk: '>=1.22.1 <2.0.0'
sdk: '>=2.0.0-dev.20.0 <2.0.0'

dependencies:
meta: ^1.1.0
Expand Down

0 comments on commit 7ad1906

Please sign in to comment.