pub fn flat_map<TFn: 'static+Fn(CellRef) -> Result<BitCodeMonad, RuntimeError>+Send+Sync>(mut self, fun: TFn) -> Result<BitCodeMonad, RuntimeError> {
        match self.value {
            BitCodeValue::AllocLabel => {
                // Labels are given a fixed value as soon as flat_map is called
                let label       = SafasCell::Any(Box::new(Label::new()));
                let mut next    = fun(label.into())?;
                next.prepend_bitcode(self.bitcode);

                Ok(next)
            },

            BitCodeValue::Value(const_value) => {
                // If this just has a constant value, we can map the bitcode immediately and combine the bitcode to get the result
                let mut next = fun(const_value)?;
                next.prepend_bitcode(self.bitcode);

                Ok(next)
            },

            BitCodeValue::FlatMap(initial, mut mappings) => {
                mappings.push(Arc::new(fun));
                self.value = BitCodeValue::FlatMap(initial, mappings);
                Ok(self)
            },

            _ => {
                // Return a flatmapped bitcode monad
                Ok(BitCodeMonad {
                    value:              BitCodeValue::FlatMap(Arc::new(self), vec![Arc::new(fun)]),
                    bitcode:            BitCodeContent::Empty,
                    following_bitcode:  BitCodeContent::Empty
                })
            }
        }
    }
///
/// Maps this monad by applying a function to the value it contains
///
Maps this monad by applying a function to the value it contains
Maps this monad by applying a function to the value it contains
pub fn flat_map<TFn: 'static+Fn(CellRef) -> Result<BitCodeMonad, RuntimeError>+Send+Sync>(mut self, fun: TFn) -> Result<BitCodeMonad, RuntimeError> {
        match self.value {
            BitCodeValue::AllocLabel => {
                // Labels are given a fixed value as soon as flat_map is called
                let label       = SafasCell::Any(Box::new(Label::new()));
                let mut next    = fun(label.into())?;
                next.prepend_bitcode(self.bitcode);
                Ok(next)
            },
            BitCodeValue::Value(const_value) => {
                // If this just has a constant value, we can map the bitcode immediately and combine the bitcode to get the result
                let mut next = fun(const_value)?;
                next.prepend_bitcode(self.bitcode);
                Ok(next)
            },
            BitCodeValue::FlatMap(initial, mut mappings) => {
                mappings.push(Arc::new(fun));
                self.value = BitCodeValue::FlatMap(initial, mappings);
                Ok(self)
            },
            _ => {
                // Return a flatmapped bitcode monad
                Ok(BitCodeMonad {
                    value:              BitCodeValue::FlatMap(Arc::new(self), vec![Arc::new(fun)]),
                    bitcode:            BitCodeContent::Empty,
                    following_bitcode:  BitCodeContent::Empty
                })
            }
        }
    }
pub fn flat_map < TFn : ' static + Fn ( CellRef ) -> Result < BitCodeMonad , RuntimeError > + Send + Sync > ( mut self , fun : TFn ) -> Result < BitCodeMonad , RuntimeError > { match self . value { BitCodeValue :: AllocLabel => { // Labels are given a fixed value as soon as flat_map is called let label = SafasCell :: Any ( Box :: new ( Label :: new ( ) ) ) ; let mut next = fun ( label . into ( ) ) ? ; next . prepend_bitcode ( self . bitcode ) ; Ok ( next ) } , BitCodeValue :: Value ( const_value ) => { // If this just has a constant value, we can map the bitcode immediately and combine the bitcode to get the result let mut next = fun ( const_value ) ? ; next . prepend_bitcode ( self . bitcode ) ; Ok ( next ) } , BitCodeValue :: FlatMap ( initial , mut mappings ) => { mappings . push ( Arc :: new ( fun ) ) ; self . value = BitCodeValue :: FlatMap ( initial , mappings ) ; Ok ( self ) } , _ => { // Return a flatmapped bitcode monad Ok ( BitCodeMonad { value : BitCodeValue :: FlatMap ( Arc :: new ( self ) , vec ! [ Arc new ( fun ) ] ) , bitcode : BitCodeContent :: Empty , following_bitcode : BitCodeContent :: Empty } ) } } }
Maps this monad by applying a function to the value it contains
Maps this monad by applying a function to the value it contains
mut self
fun
TFn
mut self
fun
TFn