26
26
import com .spotify .flo .Task ;
27
27
import com .spotify .flo .TaskContextStrict ;
28
28
import java .util .Optional ;
29
- import java .util .function .Function ;
30
29
import org .slf4j .Logger ;
31
30
import org .slf4j .LoggerFactory ;
32
31
@@ -46,21 +45,30 @@ public static EvalContext composeWith(EvalContext baseContext) {
46
45
47
46
@ Override
48
47
public <T > Value <T > evaluateInternal (Task <T > task , EvalContext context ) {
49
- final Optional <T > lookup =
48
+ final Optional <? extends TaskContextStrict <?, T >> taskContextStrict =
50
49
task .contexts ().stream ()
51
50
.filter (c -> c instanceof TaskContextStrict )
52
51
.map (c -> (TaskContextStrict <?, T >) c )
53
- .map (l -> l .lookup (task ))
54
- .findFirst ()
55
- .flatMap (Function .identity ());
52
+ .findFirst ();
56
53
57
- if (lookup .isPresent ()) {
58
- final T t = lookup .get ();
59
- LOG .debug ("Not expanding {}, lookup = {}" , colored (task .id ()), t );
60
- return context .immediateValue (t );
54
+ if (taskContextStrict .isPresent ()) {
55
+ return context .value (() -> taskContextStrict .get ().lookup (task ))
56
+ .flatMap (v -> {
57
+ if (v .isPresent ()) {
58
+ final T t = v .get ();
59
+ LOG .debug ("Not expanding {}, lookup = {}" , colored (task .id ()), t );
60
+ return context .immediateValue (t );
61
+ } else {
62
+ return delegateEvaluation (task , context );
63
+ }
64
+ });
61
65
} else {
62
- LOG .debug ("Expanding {}" , colored (task .id ()));
63
- return delegate .evaluateInternal (task , context );
66
+ return delegateEvaluation (task , context );
64
67
}
65
68
}
69
+
70
+ private <T > Value <T > delegateEvaluation (Task <T > task , EvalContext context ) {
71
+ LOG .debug ("Expanding {}" , colored (task .id ()));
72
+ return delegate .evaluateInternal (task , context );
73
+ }
66
74
}
0 commit comments