Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.

Commit 2daa611

Browse files
committed
1.1.0
1 parent 2af855e commit 2daa611

File tree

7 files changed

+55
-8
lines changed

7 files changed

+55
-8
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.1.0
2+
add trySetValFn
3+
add test
4+
add index
5+
fix example
6+
17
# 1.0.1
28
Fix lib/src/api.dart. (-1 points)
39

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ final out = Out<bool>();
1616
1717
tryDoSome(out);
1818
19-
out.val // true
19+
out.val; // true
2020
```
2121

2222
---
2323
```dart
2424
void addRef(Ref<int> ref) {
25-
tryChangeVal(ref, (val) => val++);
25+
tryChangeVal(ref, (val) => val + 1);
2626
}
2727
```
2828
```dart
@@ -31,5 +31,5 @@ final ref = Ref(1);
3131
addRef(ref);
3232
addRef(ref);
3333
34-
ref.val // 3
34+
ref.val; // 3
3535
```

example/example.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ final out = Out<bool>();
99
1010
tryDoSome(out);
1111
12-
out.val // true
12+
out.val; // true
1313
```
1414

1515
---
1616
```dart
1717
void addRef(Ref<int> ref) {
18-
tryChangeVal(ref, (val) => val++);
18+
tryChangeVal(ref, (val) => val + 1);
1919
}
2020
```
2121
```dart
@@ -24,5 +24,5 @@ final ref = Ref(1);
2424
addRef(ref);
2525
addRef(ref);
2626
27-
ref.val // 3
27+
ref.val; // 3
2828
```

lib/index.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export './ref_out_box.dart';
2+
export './api.dart';

lib/src/api.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ bool trySetVal<T>(Out<T> out, T val) {
1111
return true;
1212
}
1313

14+
/// Try setting the wrapper box value
15+
/// Can avoid null problems
16+
/// Return whether the setting is successful
17+
bool trySetValFn<T>(Out<T> out, T fn()) {
18+
if (out == null || fn == null) return false;
19+
out.val = fn();
20+
return true;
21+
}
22+
1423
/// Try change the wrapper box value
1524
/// Can avoid null problems
1625
/// Return whether the setting is successful
@@ -30,4 +39,4 @@ Maybe<R> tryUseVal<T, R>(Box<T> box, R fn(T val)) {
3039
Maybe<T> toMaybe<T>(Box<T> box) {
3140
if (box == null) return None<T>();
3241
return Some<T>(box.val);
33-
}
42+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: ref_out_box
2-
version: '1.0.1'
2+
version: '1.1.0'
33
description: "Wrapping values so that they can be passed by reference, like c#'s ref out"
44
authors:
55
- 'MeowType <[email protected]>'

test/base_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:test/test.dart';
2+
3+
import 'package:ref_out_box/index.dart';
4+
5+
void main() {
6+
test('Out', () {
7+
void tryDoSome(Out<bool> out) {
8+
trySetVal(out, true);
9+
}
10+
11+
final out = Out<bool>();
12+
13+
tryDoSome(out);
14+
15+
expect(out.val, isTrue);
16+
});
17+
18+
test('Ref', () {
19+
void addRef(Ref<int> ref) {
20+
tryChangeVal(ref, (val) => val + 1);
21+
}
22+
23+
final ref = Ref(1);
24+
25+
addRef(ref);
26+
addRef(ref);
27+
28+
expect(ref.val, equals(3));
29+
});
30+
}

0 commit comments

Comments
 (0)