contain-rs / compare Goto Github PK
View Code? Open in Web Editor NEWExperimental comparators for collections to be generic over
Home Page: https://contain-rs.github.io/compare/compare
License: Apache License 2.0
Experimental comparators for collections to be generic over
Home Page: https://contain-rs.github.io/compare/compare
License: Apache License 2.0
Convert {max, min, Extract::new}
to default methods on Compare
once where clauses permit equality constraints.
Blocked on rust-lang/rust#20041.
These can be copied from collect-rs
.
Blocked on rust-lang/rust#7671.
Instead of using my (or @gankro's) personal access token as the value of the GH_TOKEN
environment variable on Travis CI, we should create one from @FlashCat's GitHub account. This will limit the consequences of the token being compromised.
Whoever has FlashCat's GitHub credentials should do the following:
public_repo
permission.GH_TOKEN
environment variable by visiting https://travis-ci.org/contain-rs/compare/settings/env_vars.GH_TOKEN
environment variable with the token that was copied, ensuring that the "Display value in build logs" settings is "OFF" (which it is by default).contain-rs
repos.The only reason this type parameter is currently necessary is because of the design of the comparator adaptors. Without the parameter (and replacing the natural
function with a unit struct), the extremely common
let cmp = Natural.rev();
assert_eq!(cmp.compare(&1, &2), Greater);
fails type inference:
error: type annotations required: cannot resolve `_ : core::cmp::Ord` [E0283]
let cmp = Natural.rev();
^~~~~
This is because the rev
method is defined on the Compare
trait itself, which has two type parameters (for the left- and right-hand sides of the comparison), and the specific impl to use here is unconstrained.
However, the behavior of the rev
method is always the same, regardless of the concrete comparator type or the type parameters involved. Therefore, there should really only be one way (impl) to reverse a comparator, which leads to a few possible solutions. They cannot involve type parameters on Compare
.
Freestanding function:
pub struct Rev<C>(C);
pub fn rev<C>(cmp: C) -> Rev<C>);
Constructor method:
pub struct Rev<C>(C);
impl<C> Rev<C> {
pub fn new(cmp: C) -> Rev<C> { Rev(cmp) }
}
Public field:
pub struct Rev<C>(pub C);
This approach has the following downsides:
The user must import an additional type or function for each adaptor. (This is potentially negated by the custom prelude RFC).
Chaining is no longer possible, which can make things confusing. For example:
let cmp = then(extract(SliceExt::len, rev(Natural))), extract(SliceExt::first, Natural));
versus
let cmp = Natural.rev().extract(SliceExt::len).then(Natural.extract(SliceExt::first));
pub trait CompareExt: Sized { // note that it does not extend `Compare`
fn rev(self) -> Rev<C> { Rev(self) }
... // methods for other adaptors
}
With a blanket impl:
impl<C> CompareExt for C {} // note that we cannot specify `C: Compare<L, R>`
With specific impls:
impl CompareExt for Natural {}
impl<C> CompareExt for Rev<C> {}
...
TODO: Other options.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.