-
Notifications
You must be signed in to change notification settings - Fork 5
StreamMatchers.empty() and StreamMatchers.equalTo() return Matcher<BaseStream<T, S>> #18
StreamMatchers.empty() and StreamMatchers.equalTo() return Matcher<BaseStream<T, S>> #18
Comments
I think this is a reasonable change, as one should rarely reference I did some testing with a bit esoteric use of types, inferred through multiple methods, and found that the following does not compile with the proposed changes: BaseStream<Character, Stream<Character>> expectedBaseStream = Stream.of('x', 'y', 'z');
assertThat("xyz", where(s -> s.chars().mapToObj(i -> (char) i), equalTo(expectedBaseStream)));
DescribableFunction<String, BaseStream<Character, Stream<Character>>> characters = s -> s.chars().mapToObj(i -> (char) i);
assertThat("xyz", where(characters, equalTo(Stream.of('x', 'y', 'z')))); I still think this change makes sense, as the returned matcher should be as specifically typed as possible, and the matcher should be of the same type as the given argument. I.e. The typing can be easily fixed by changing the signature of public static <T,S extends BaseStream<T, ? extends S>> Matcher<S> equalTo(S expected) Adding the @facboy For completeness, can you give a concrete example of code which fails to compile with the existing type signature of |
i haven't had time to look at this yet. |
Return type is parameterized to yield a Matcher of the specific Stream-type, instead of just Matcher<BaseStream<_, _>>. See unruly/java-8-matchers#18 for more detailed discussion.
Return type is parameterized to yield a Matcher of the specific Stream-type, instead of just Matcher<BaseStream<_, _>>. See unruly/java-8-matchers#18 for more detailed discussion.
I think it would be better if
StreamMatchers.empty()
andStreamMatchers.equalTo()
returnedMatcher<S>
, this would make them usable with a wider range of methods (in particular, methods that expect aStream<T>
argument).The text was updated successfully, but these errors were encountered: