fn execute(&self, frame: Frame) -> (Frame, Self::Binding) {
        // Arguments should be flat_map arguments (we expect to be called via flat_map in MonadType)
        let args = frame.cells[0].clone();
        let args = match FlatMapArgs::try_from(args) { Ok(args) => args, Err(err) => return (frame, Err(err)) };

        // This should be called on a bitcode monad, so we should be able to retrieve this from the monad cell
        let bitcode_monad = BitCodeMonad::from_cell(&args.monad_value);

        // Replace the empty bitcode monad with a 'full' bitcode monad
        let bitcode_monad = bitcode_monad.unwrap_or_else(|| BitCodeMonad::empty());

        // Fetch the mapping function to apply (this is a function of the form 'x -> <Monad>', where <Monad> is another bitcode monad)
        let map_fn = args.map_fn;

        // Applying the map function should return the updated monad
        let next                = bitcode_monad.flat_map(move |val| {
            // Fetch the map function
            let map_fn = match &*map_fn {
                SafasCell::FrameMonad(monad_fn) => monad_fn,
                _                               => return Err(RuntimeError::NotAFunction(map_fn.clone()))
            };

            // Create a new frame to execute the map function on and execute it
            let mut frame           = Frame::new(1, None);
            frame.cells[0]          = SafasCell::List(val, NIL.clone()).into();
            let (_frame, next)      = map_fn.execute(frame);

            let next                = match next { Ok(next) => next, Err(err) => return Err(err) };

            // Result of the map function should either be a bitcode monad or nil
            let next_monad          = BitCodeMonad::from_cell(&next);

            let next_monad          = match next_monad {
                Some(next_monad)    => next_monad,
                None                => return Err(RuntimeError::MismatchedMonad(next))
            };

            Ok(next_monad)
        });
        let next                = match next { Ok(next) => next, Err(err) => return (frame, Err(err)) };

        // Wrap the resulting monad to generate the return value
        let result = SafasCell::Any(Box::new(next)).into();
        (frame, Ok(SafasCell::Monad(result, MonadType::new(BITCODE_FLAT_MAP.clone())).into()))
    }
/// Executes this monad against a frame
Executes this monad against a frame
Executes this monad against a frame
fn execute(&self, frame: Frame) -> (Frame, Self::Binding) {
        // Arguments should be flat_map arguments (we expect to be called via flat_map in MonadType)
        let args = frame.cells[0].clone();
        let args = match FlatMapArgs::try_from(args) { Ok(args) => args, Err(err) => return (frame, Err(err)) };
        // This should be called on a bitcode monad, so we should be able to retrieve this from the monad cell
        let bitcode_monad = BitCodeMonad::from_cell(&args.monad_value);
        // Replace the empty bitcode monad with a 'full' bitcode monad
        let bitcode_monad = bitcode_monad.unwrap_or_else(|| BitCodeMonad::empty());
        // Fetch the mapping function to apply (this is a function of the form 'x -> <Monad>', where <Monad> is another bitcode monad)
        let map_fn = args.map_fn;
        // Applying the map function should return the updated monad
        let next                = bitcode_monad.flat_map(move |val| {
            // Fetch the map function
            let map_fn = match &*map_fn {
                SafasCell::FrameMonad(monad_fn) => monad_fn,
                _                               => return Err(RuntimeError::NotAFunction(map_fn.clone()))
            };
            // Create a new frame to execute the map function on and execute it
            let mut frame           = Frame::new(1, None);
            frame.cells[0]          = SafasCell::List(val, NIL.clone()).into();
            let (_frame, next)      = map_fn.execute(frame);
            let next                = match next { Ok(next) => next, Err(err) => return Err(err) };
            // Result of the map function should either be a bitcode monad or nil
            let next_monad          = BitCodeMonad::from_cell(&next);
            let next_monad          = match next_monad {
                Some(next_monad)    => next_monad,
                None                => return Err(RuntimeError::MismatchedMonad(next))
            };
            Ok(next_monad)
        });
        let next                = match next { Ok(next) => next, Err(err) => return (frame, Err(err)) };
        // Wrap the resulting monad to generate the return value
        let result = SafasCell::Any(Box::new(next)).into();
        (frame, Ok(SafasCell::Monad(result, MonadType::new(BITCODE_FLAT_MAP.clone())).into()))
    }
fn execute ( & self , frame : Frame ) -> ( Frame , Self :: Binding ) { // Arguments should be flat_map arguments (we expect to be called via flat_map in MonadType) let args = frame . cells [ 0 ] . clone ( ) ; let args = match FlatMapArgs :: try_from ( args ) { Ok ( args ) => args , Err ( err ) => return ( frame , Err ( err ) ) } ; // This should be called on a bitcode monad, so we should be able to retrieve this from the monad cell let bitcode_monad = BitCodeMonad :: from_cell ( & args . monad_value ) ; // Replace the empty bitcode monad with a 'full' bitcode monad let bitcode_monad = bitcode_monad . unwrap_or_else ( | | BitCodeMonad :: empty ( ) ) ; // Fetch the mapping function to apply (this is a function of the form 'x -> <Monad>', where <Monad> is another bitcode monad) let map_fn = args . map_fn ; // Applying the map function should return the updated monad let next = bitcode_monad . flat_map ( move | val | { // Fetch the map function let map_fn = match & * map_fn { SafasCell :: FrameMonad ( monad_fn ) => monad_fn , _ => return Err ( RuntimeError :: NotAFunction ( map_fn . clone ( ) ) ) } ; // Create a new frame to execute the map function on and execute it let mut frame = Frame :: new ( 1 , None ) ; frame . cells [ 0 ] = SafasCell :: List ( val , NIL . clone ( ) ) . into ( ) ; let ( _frame , next ) = map_fn . execute ( frame ) ; let next = match next { Ok ( next ) => next , Err ( err ) => return Err ( err ) } ; // Result of the map function should either be a bitcode monad or nil let next_monad = BitCodeMonad :: from_cell ( & next ) ; let next_monad = match next_monad { Some ( next_monad ) => next_monad , None => return Err ( RuntimeError :: MismatchedMonad ( next ) ) } ; Ok ( next_monad ) } ) ; let next = match next { Ok ( next ) => next , Err ( err ) => return ( frame , Err ( err ) ) } ; // Wrap the resulting monad to generate the return value let result = SafasCell :: Any ( Box :: new ( next ) ) . into ( ) ; ( frame , Ok ( SafasCell :: Monad ( result , MonadType :: new ( BITCODE_FLAT_MAP . clone ( ) ) ) . into ( ) ) ) }
Executes this monad against a frame
Executes this monad against a frame
&self
frame
Frame
&self
frame
Frame