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>>,
|
||||
) -> Resolution<'a, Ctx, A> {
|
||||
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 mentionable = origin
|
||||
.r_factory
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
use std::convert::identity;
|
||||
|
||||
use crate::func::context::*;
|
||||
use crate::rcore::*;
|
||||
|
||||
use super::{typeless::*, wrapped_origin::*, *};
|
||||
@ -65,7 +66,7 @@ impl<'a> CastError<'a> {
|
||||
where
|
||||
Ctx::LookupError: From<CastError<'a>>,
|
||||
{
|
||||
Ctx::T::pure(Err(self.into()))
|
||||
Ctx::pure(Err(self.into()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +144,7 @@ where
|
||||
Ok(point) => point,
|
||||
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
|
||||
Ctx::LookupError: From<CastError<'a>>,
|
||||
{
|
||||
Ctx::T::fmap(
|
||||
Ctx::fmap(
|
||||
typeless_origin.clone().resolve(),
|
||||
move |resolved| match resolved {
|
||||
Ok(typeless_mentionable) => match typeless_mentionable.cast(factory) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::func::*;
|
||||
use crate::func::context::*;
|
||||
|
||||
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> {
|
||||
pub fn resolve(&self) -> Resolution<'a, Ctx, AvlNode<'a, Ctx, A>> {
|
||||
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?;
|
||||
node.matches_height(parent_height)
|
||||
.map_err(ResolutionError::Parse)?;
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::flow::comparator::*;
|
||||
use crate::func::*;
|
||||
use crate::func::context::*;
|
||||
|
||||
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> {
|
||||
match self.into_tree() {
|
||||
Ok(tree) => <Ctx::T as Pure>::pure(Ok(tree)),
|
||||
Err(e) => <Ctx::T as Pure>::pure(Err(ResolutionError::Parse(e))),
|
||||
Ok(tree) => Ctx::pure(Ok(tree)),
|
||||
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>,
|
||||
comparator: Rc<impl 'a + Comparator<A>>,
|
||||
) -> BrKeySplit<'a, Ctx, A> {
|
||||
<Ctx::T as Pure>::pure(
|
||||
Ctx::pure(
|
||||
Self::split_empty(self.bounds, &key, &factory, comparator.as_ref())
|
||||
.map_err(BoundError::Bounds)
|
||||
.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> {
|
||||
pub fn resolve(&self, comparator: Rc<impl 'a + Comparator<A>>) -> BrNode<'a, Ctx, A> {
|
||||
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
|
||||
.map_err(|e| e.map_parse(BoundError::Avl))?
|
||||
.as_ref()
|
||||
|
@ -1,5 +1,6 @@
|
||||
//! Basic implementation of a stack/linked list.
|
||||
|
||||
use crate::func::context::*;
|
||||
use crate::rcore::*;
|
||||
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> {
|
||||
Ctx::T::iterate_mut((vec![], self), |(mut vec, stack)| match stack {
|
||||
Nullable::Null(_) => Ctx::T::pure(ControlFlow::Break(Ok(vec))),
|
||||
Nullable::NotNull(point) => Ctx::T::fmap(point.resolve(), |resolved| {
|
||||
Nullable::Null(_) => Ctx::pure(ControlFlow::Break(Ok(vec))),
|
||||
Nullable::NotNull(point) => Ctx::fmap(point.resolve(), |resolved| {
|
||||
let node = match resolved {
|
||||
Ok(node) => node,
|
||||
Err(error) => {
|
||||
|
@ -1,7 +1,6 @@
|
||||
//! Shorthands for using [`Context::Fallible`].
|
||||
|
||||
#[cfg(doc)]
|
||||
use crate::func::context::FunctorContext;
|
||||
use crate::func::context::*;
|
||||
|
||||
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].
|
||||
pub trait FallibleContext<'a>: Context<'a> {
|
||||
/// Convert a fallible wrapped into a wrapped result.
|
||||
fn unstuff<A: 'a, E: 'a>(
|
||||
wa: WrapE<'a, A, E, Self::Fallible>,
|
||||
) -> Wrap<'a, Result<A, E>, Self::T> {
|
||||
fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self::Fallible>) -> WrapC<'a, Result<A, E>, Self> {
|
||||
Self::Fallible::unstuff(wa)
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::func::context::*;
|
||||
use crate::rcore::*;
|
||||
|
||||
use super::*;
|
||||
|
||||
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
|
||||
fn prepare_bytes_for_hashing(mentioned: &A) -> Vec<u8> {
|
||||
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> {
|
||||
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`].
|
||||
|
||||
use crate::func::context::*;
|
||||
use crate::rcore::*;
|
||||
|
||||
use super::{inlining::*, point::*, *};
|
||||
@ -80,7 +81,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, Nullable<'
|
||||
match self {
|
||||
Self::Null(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(),
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use crate::func::context::*;
|
||||
|
||||
use super::*;
|
||||
|
||||
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_err: impl 'a + Fn(ParseError<'a, Ctx, A::Fctr>) -> ParseError<'a, Ctx, B::Fctr>,
|
||||
) -> 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))),
|
||||
Err(e) => Err(e.map_parse(map_err)),
|
||||
})
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::func::*;
|
||||
use crate::func::context::*;
|
||||
use crate::rcore::*;
|
||||
|
||||
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> {
|
||||
fn resolve(self: Rc<Self>, address: crate::rcore::Address) -> HashResolution<'a, Ctx> {
|
||||
let inject = self.inject.clone();
|
||||
<Ctx::T as Functor>::fmap(
|
||||
Ctx::fmap(
|
||||
self.resolver.clone().resolve(address),
|
||||
|resolved| match resolved {
|
||||
Ok((source, resolver)) => Ok((
|
||||
|
Loading…
Reference in New Issue
Block a user