Pre: move Either to mentat_core::util.

This commit is contained in:
Richard Newman 2017-06-14 14:42:34 -07:00
parent 03c0930285
commit c2ec1a6bdf
4 changed files with 39 additions and 31 deletions

View file

@ -56,4 +56,33 @@ impl<T> OptionEffect<T> for Option<T> {
}
self
}
}
}
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum Either<L, R> {
Left(L),
Right(R),
}
// Cribbed from https://github.com/bluss/either/blob/f793721f3fdeb694f009e731b23a2858286bc0d6/src/lib.rs#L219-L259.
impl<L, R> Either<L, R> {
pub fn map_left<F, M>(self, f: F) -> Either<M, R>
where F: FnOnce(L) -> M
{
use self::Either::*;
match self {
Left(l) => Left(f(l)),
Right(r) => Right(r),
}
}
pub fn map_right<F, S>(self, f: F) -> Either<L, S>
where F: FnOnce(R) -> S
{
use self::Either::*;
match self {
Left(l) => Left(l),
Right(r) => Right(f(r)),
}
}
}

View file

@ -15,6 +15,8 @@
use std::collections::HashMap;
use std::rc::Rc;
use mentat_core::util::Either;
use errors;
use errors::ErrorKind;
use types::{
@ -33,33 +35,6 @@ pub enum Term<E, V> {
AddOrRetract(OpType, E, Entid, V),
}
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd, PartialEq)]
pub enum Either<L, R> {
Left(L),
Right(R),
}
// Cribbed from https://github.com/bluss/either/blob/f793721f3fdeb694f009e731b23a2858286bc0d6/src/lib.rs#L219-L259.
impl<L, R> Either<L, R> {
pub fn map_left<F, M>(self, f: F) -> Either<M, R>
where F: FnOnce(L) -> M
{
match self {
Left(l) => Left(f(l)),
Right(r) => Right(r),
}
}
pub fn map_right<F, S>(self, f: F) -> Either<L, S>
where F: FnOnce(R) -> S
{
match self {
Left(l) => Left(l),
Right(r) => Right(f(r)),
}
}
}
use self::Either::*;
/// An entid that's either already in the store, or newly allocated to a tempid.

View file

@ -64,7 +64,6 @@ use edn::{
use entids;
use errors::{ErrorKind, Result};
use internal_types::{
Either,
KnownEntid,
KnownEntidOr,
LookupRef,
@ -76,7 +75,10 @@ use internal_types::{
TermWithTempIdsAndLookupRefs,
TermWithoutTempIds,
TypedValueOr,
replace_lookup_ref};
replace_lookup_ref,
};
use mentat_core::util::Either;
use mentat_core::{
DateTime,

View file

@ -28,7 +28,9 @@ use internal_types::{
TermWithoutTempIds,
TermWithTempIds,
};
use internal_types::Either::*;
use mentat_core::util::Either::*;
use mentat_core::{
attribute,
Attribute,