Skip to main content

duplicate

Function duplicate 

Source
pub fn duplicate<'a, Brand: Extend, A: 'a + Clone>(
    wa: <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>,
) -> <Brand as Kind_cdc7cd43dac7585f>::Of<'a, <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>>
where <Brand as Kind_cdc7cd43dac7585f>::Of<'a, A>: 'a,
Expand description

Duplicates a comonadic context, wrapping it inside another layer of the same context.

duplicate(wa) is equivalent to extend(identity, wa). It is the dual of join for monads.

Produces F<F<A>> from F<A>, embedding the original context as the inner value.

§Type Signature

forall Brand A. Extend Brand => Brand A -> Brand (Brand A)

§Type Parameters

  • 'a: The lifetime of the values.
  • Brand: The brand of the comonadic context.
  • A: The type of the value(s) inside the comonadic context.

§Parameters

  • wa: The comonadic context to duplicate.

§Returns

A doubly-wrapped comonadic context.

§Examples

use fp_library::{
	brands::*,
	functions::*,
};

// duplicate on Vec produces all suffixes
let v = vec![1, 2, 3];
let d = duplicate::<VecBrand, _>(v);
assert_eq!(d, vec![vec![1, 2, 3], vec![2, 3], vec![3]]);