Skip to content

Instantly share code, notes, and snippets.

@jimblandy
Created February 27, 2019 02:52
Show Gist options
  • Save jimblandy/5a6776168866569def6be7b7279e372a to your computer and use it in GitHub Desktop.
Save jimblandy/5a6776168866569def6be7b7279e372a to your computer and use it in GitHub Desktop.
How would you go about implementing `squeeze`?
#[cfg(test)]
mod test {
use super::squeeze;
#[test]
fn test_squeeze() {
// The idea here is that any non-() type would work.
assert_eq!(squeeze(1i32, 2i32), (1, 2));
assert_eq!(squeeze(true, false), (true, false));
assert_eq!(squeeze("foo", Some("bar")), ("foo", Some("bar")));
assert_eq!(squeeze(1i32, ()), 1);
assert_eq!(squeeze("foo", ()), "foo");
assert_eq!(squeeze(Some(1.3), ()), Some(1.3));
assert_eq!(squeeze((), 2i32), 2);
assert_eq!(squeeze((), "foo"), "foo");
assert_eq!(squeeze((), Some(1.3)), Some(1.3));
assert_eq!(squeeze((), ()), ());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment