more func:context
usage
This commit is contained in:
parent
277bea3eb3
commit
692802f5de
@ -28,7 +28,7 @@ fn _resolve_origin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
|
|||||||
origin: Rc<ResolverOrigin<'a, Ctx, A::Fctr>>,
|
origin: Rc<ResolverOrigin<'a, Ctx, A::Fctr>>,
|
||||||
) -> Resolution<'a, Ctx, A> {
|
) -> Resolution<'a, Ctx, A> {
|
||||||
let resolution = origin.r_resolver.clone().resolve(origin.r_address);
|
let resolution = origin.r_resolver.clone().resolve(origin.r_address);
|
||||||
Ctx::T::fmap(resolution, move |resolved| {
|
Ctx::fmap(resolution, move |resolved| {
|
||||||
let (src, resolver) = resolved.map_err(ResolutionError::Lookup)?;
|
let (src, resolver) = resolved.map_err(ResolutionError::Lookup)?;
|
||||||
let mentionable = origin
|
let mentionable = origin
|
||||||
.r_factory
|
.r_factory
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
use std::convert::identity;
|
use std::convert::identity;
|
||||||
|
|
||||||
|
use crate::func::context::*;
|
||||||
use crate::rcore::*;
|
use crate::rcore::*;
|
||||||
|
|
||||||
use super::{typeless::*, wrapped_origin::*, *};
|
use super::{typeless::*, wrapped_origin::*, *};
|
||||||
@ -65,7 +66,7 @@ impl<'a> CastError<'a> {
|
|||||||
where
|
where
|
||||||
Ctx::LookupError: From<CastError<'a>>,
|
Ctx::LookupError: From<CastError<'a>>,
|
||||||
{
|
{
|
||||||
Ctx::T::pure(Err(self.into()))
|
Ctx::pure(Err(self.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +144,7 @@ where
|
|||||||
Ok(point) => point,
|
Ok(point) => point,
|
||||||
Err(cast_error) => return cast_error.pure::<Ctx>(),
|
Err(cast_error) => return cast_error.pure::<Ctx>(),
|
||||||
};
|
};
|
||||||
Ctx::T::fmap(point.resolve(), cast_resolved)
|
Ctx::fmap(point.resolve(), cast_resolved)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +179,7 @@ fn cast_resolve<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
|
|||||||
where
|
where
|
||||||
Ctx::LookupError: From<CastError<'a>>,
|
Ctx::LookupError: From<CastError<'a>>,
|
||||||
{
|
{
|
||||||
Ctx::T::fmap(
|
Ctx::fmap(
|
||||||
typeless_origin.clone().resolve(),
|
typeless_origin.clone().resolve(),
|
||||||
move |resolved| match resolved {
|
move |resolved| match resolved {
|
||||||
Ok(typeless_mentionable) => match typeless_mentionable.cast(factory) {
|
Ok(typeless_mentionable) => match typeless_mentionable.cast(factory) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::func::*;
|
use crate::func::context::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> AvlTree<'a, Ctx, A> {
|
|||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> AvlReference<'a, Ctx, A> {
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> AvlReference<'a, Ctx, A> {
|
||||||
pub fn resolve(&self) -> Resolution<'a, Ctx, AvlNode<'a, Ctx, A>> {
|
pub fn resolve(&self) -> Resolution<'a, Ctx, AvlNode<'a, Ctx, A>> {
|
||||||
let parent_height = self.parent_height;
|
let parent_height = self.parent_height;
|
||||||
<Ctx::T as Functor>::fmap(self.node.resolve(), move |resolved| {
|
Ctx::fmap(self.node.resolve(), move |resolved| {
|
||||||
let node = resolved?;
|
let node = resolved?;
|
||||||
node.matches_height(parent_height)
|
node.matches_height(parent_height)
|
||||||
.map_err(ResolutionError::Parse)?;
|
.map_err(ResolutionError::Parse)?;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::flow::comparator::*;
|
use crate::flow::comparator::*;
|
||||||
use crate::func::*;
|
use crate::func::context::*;
|
||||||
|
|
||||||
use super::{binary::*, *};
|
use super::{binary::*, *};
|
||||||
|
|
||||||
@ -152,8 +152,8 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> BoundNode<'a, Ctx, A> {
|
|||||||
|
|
||||||
pub fn into_tree_resolution(self) -> BrTree<'a, Ctx, A> {
|
pub fn into_tree_resolution(self) -> BrTree<'a, Ctx, A> {
|
||||||
match self.into_tree() {
|
match self.into_tree() {
|
||||||
Ok(tree) => <Ctx::T as Pure>::pure(Ok(tree)),
|
Ok(tree) => Ctx::pure(Ok(tree)),
|
||||||
Err(e) => <Ctx::T as Pure>::pure(Err(ResolutionError::Parse(e))),
|
Err(e) => Ctx::pure(Err(ResolutionError::Parse(e))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> BoundTree<'a, Ctx, A> {
|
|||||||
factory: Fctr<'a, Ctx, A>,
|
factory: Fctr<'a, Ctx, A>,
|
||||||
comparator: Rc<impl 'a + Comparator<A>>,
|
comparator: Rc<impl 'a + Comparator<A>>,
|
||||||
) -> BrKeySplit<'a, Ctx, A> {
|
) -> BrKeySplit<'a, Ctx, A> {
|
||||||
<Ctx::T as Pure>::pure(
|
Ctx::pure(
|
||||||
Self::split_empty(self.bounds, &key, &factory, comparator.as_ref())
|
Self::split_empty(self.bounds, &key, &factory, comparator.as_ref())
|
||||||
.map_err(BoundError::Bounds)
|
.map_err(BoundError::Bounds)
|
||||||
.map_err(ResolutionError::Parse),
|
.map_err(ResolutionError::Parse),
|
||||||
@ -251,7 +251,7 @@ pub type BrKeySplit<'a, Ctx, A> = BoundResolution<'a, Ctx, A, BoundKeySplit<'a,
|
|||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> BoundReference<'a, Ctx, A> {
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> BoundReference<'a, Ctx, A> {
|
||||||
pub fn resolve(&self, comparator: Rc<impl 'a + Comparator<A>>) -> BrNode<'a, Ctx, A> {
|
pub fn resolve(&self, comparator: Rc<impl 'a + Comparator<A>>) -> BrNode<'a, Ctx, A> {
|
||||||
let bounds = self.bounds.clone();
|
let bounds = self.bounds.clone();
|
||||||
<Ctx::T as Functor>::fmap(self.reference.resolve(), move |resolved| {
|
Ctx::fmap(self.reference.resolve(), move |resolved| {
|
||||||
let node = resolved
|
let node = resolved
|
||||||
.map_err(|e| e.map_parse(BoundError::Avl))?
|
.map_err(|e| e.map_parse(BoundError::Avl))?
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//! Basic implementation of a stack/linked list.
|
//! Basic implementation of a stack/linked list.
|
||||||
|
|
||||||
|
use crate::func::context::*;
|
||||||
use crate::rcore::*;
|
use crate::rcore::*;
|
||||||
use crate::rstd::{inlining::*, nullable::*, point::*, *};
|
use crate::rstd::{inlining::*, nullable::*, point::*, *};
|
||||||
|
|
||||||
@ -156,8 +157,8 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for Sta
|
|||||||
}
|
}
|
||||||
fn vec(self) -> StackVecWrapped<'a, Ctx, A> {
|
fn vec(self) -> StackVecWrapped<'a, Ctx, A> {
|
||||||
Ctx::T::iterate_mut((vec![], self), |(mut vec, stack)| match stack {
|
Ctx::T::iterate_mut((vec![], self), |(mut vec, stack)| match stack {
|
||||||
Nullable::Null(_) => Ctx::T::pure(ControlFlow::Break(Ok(vec))),
|
Nullable::Null(_) => Ctx::pure(ControlFlow::Break(Ok(vec))),
|
||||||
Nullable::NotNull(point) => Ctx::T::fmap(point.resolve(), |resolved| {
|
Nullable::NotNull(point) => Ctx::fmap(point.resolve(), |resolved| {
|
||||||
let node = match resolved {
|
let node = match resolved {
|
||||||
Ok(node) => node,
|
Ok(node) => node,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//! Shorthands for using [`Context::Fallible`].
|
//! Shorthands for using [`Context::Fallible`].
|
||||||
|
|
||||||
#[cfg(doc)]
|
use crate::func::context::*;
|
||||||
use crate::func::context::FunctorContext;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -17,14 +16,12 @@ pub type FallibleWrapped<'a, Ctx, A, E> = Wrap<'a, A, FallibleMonad<'a, Ctx, E>>
|
|||||||
/// this is the preferred way to switch between [Wrapped] and [fallible].
|
/// this is the preferred way to switch between [Wrapped] and [fallible].
|
||||||
pub trait FallibleContext<'a>: Context<'a> {
|
pub trait FallibleContext<'a>: Context<'a> {
|
||||||
/// Convert a fallible wrapped into a wrapped result.
|
/// Convert a fallible wrapped into a wrapped result.
|
||||||
fn unstuff<A: 'a, E: 'a>(
|
fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self::Fallible>) -> WrapC<'a, Result<A, E>, Self> {
|
||||||
wa: WrapE<'a, A, E, Self::Fallible>,
|
|
||||||
) -> Wrap<'a, Result<A, E>, Self::T> {
|
|
||||||
Self::Fallible::unstuff(wa)
|
Self::Fallible::unstuff(wa)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a wrapped result into a fallible wrapped.
|
/// Convert a wrapped result into a fallible wrapped.
|
||||||
fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self::Fallible> {
|
fn stuff<A: 'a, E: 'a>(fa: WrapC<'a, Result<A, E>, Self>) -> WrapE<'a, A, E, Self::Fallible> {
|
||||||
Self::Fallible::stuff(fa)
|
Self::Fallible::stuff(fa)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
use crate::func::context::*;
|
||||||
use crate::rcore::*;
|
use crate::rcore::*;
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
|
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
|
||||||
fn prepare_bytes_for_hashing(mentioned: &A) -> Vec<u8> {
|
fn prepare_bytes_for_hashing(mentioned: &A) -> Vec<u8> {
|
||||||
let mut vec = mentioned.topology().to_vec();
|
let mut vec = mentioned.topology().to_vec();
|
||||||
@ -37,7 +36,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for LocalOri
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn resolve(self: Rc<Self>) -> Resolution<'a, Ctx, Self::Mtbl> {
|
fn resolve(self: Rc<Self>) -> Resolution<'a, Ctx, Self::Mtbl> {
|
||||||
Ctx::T::pure(Ok(self.0.clone()))
|
Ctx::pure(Ok(self.0.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//! This module introduces [`Option`]-like concepts into RADN typesystem using [`Nullable`].
|
//! This module introduces [`Option`]-like concepts into RADN typesystem using [`Nullable`].
|
||||||
|
|
||||||
|
use crate::func::context::*;
|
||||||
use crate::rcore::*;
|
use crate::rcore::*;
|
||||||
|
|
||||||
use super::{inlining::*, point::*, *};
|
use super::{inlining::*, point::*, *};
|
||||||
@ -80,7 +81,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, Nullable<'
|
|||||||
match self {
|
match self {
|
||||||
Self::Null(nullable_factory) => {
|
Self::Null(nullable_factory) => {
|
||||||
let NullableFactory { factory } = nullable_factory;
|
let NullableFactory { factory } = nullable_factory;
|
||||||
Ctx::T::pure(Ok(Rc::new(Nullable::Null(factory.clone()))))
|
Ctx::pure(Ok(Rc::new(Nullable::Null(factory.clone()))))
|
||||||
}
|
}
|
||||||
Self::NotNull(point) => point.resolve(),
|
Self::NotNull(point) => point.resolve(),
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use crate::func::context::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn wrapped_origin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
|
pub fn wrapped_origin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
|
||||||
@ -42,7 +44,7 @@ fn map_resolve<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, B: Mentionable<'a,
|
|||||||
map_ok: impl 'a + Fn(Rc<A>) -> B,
|
map_ok: impl 'a + Fn(Rc<A>) -> B,
|
||||||
map_err: impl 'a + Fn(ParseError<'a, Ctx, A::Fctr>) -> ParseError<'a, Ctx, B::Fctr>,
|
map_err: impl 'a + Fn(ParseError<'a, Ctx, A::Fctr>) -> ParseError<'a, Ctx, B::Fctr>,
|
||||||
) -> Resolution<'a, Ctx, B> {
|
) -> Resolution<'a, Ctx, B> {
|
||||||
Ctx::T::fmap(resolve(), move |resolved| match resolved {
|
Ctx::fmap(resolve(), move |resolved| match resolved {
|
||||||
Ok(mentionable) => Ok(Rc::new(map_ok(mentionable))),
|
Ok(mentionable) => Ok(Rc::new(map_ok(mentionable))),
|
||||||
Err(e) => Err(e.map_parse(map_err)),
|
Err(e) => Err(e.map_parse(map_err)),
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::func::*;
|
use crate::func::context::*;
|
||||||
use crate::rcore::*;
|
use crate::rcore::*;
|
||||||
|
|
||||||
trait Inject<'a, Ctx: Context<'a>>: 'a {
|
trait Inject<'a, Ctx: Context<'a>>: 'a {
|
||||||
@ -15,7 +15,7 @@ struct InjectedResolver<'a, Ctx: Context<'a>, F: Inject<'a, Ctx>> {
|
|||||||
impl<'a, Ctx: Context<'a>, F: Inject<'a, Ctx>> Resolver<'a, Ctx> for InjectedResolver<'a, Ctx, F> {
|
impl<'a, Ctx: Context<'a>, F: Inject<'a, Ctx>> Resolver<'a, Ctx> for InjectedResolver<'a, Ctx, F> {
|
||||||
fn resolve(self: Rc<Self>, address: crate::rcore::Address) -> HashResolution<'a, Ctx> {
|
fn resolve(self: Rc<Self>, address: crate::rcore::Address) -> HashResolution<'a, Ctx> {
|
||||||
let inject = self.inject.clone();
|
let inject = self.inject.clone();
|
||||||
<Ctx::T as Functor>::fmap(
|
Ctx::fmap(
|
||||||
self.resolver.clone().resolve(address),
|
self.resolver.clone().resolve(address),
|
||||||
|resolved| match resolved {
|
|resolved| match resolved {
|
||||||
Ok((source, resolver)) => Ok((
|
Ok((source, resolver)) => Ok((
|
||||||
|
Loading…
Reference in New Issue
Block a user