fp_library/types/
string.rs

1//! Implementations for [`String`].
2
3use crate::{
4	classes::{
5		ClonableFn, Monoid, Semigroup, clonable_fn::ApplyFn, monoid::Monoid1L0T,
6		semigroup::Semigroup1L0T,
7	},
8	hkt::Kind1L0T,
9};
10
11impl Kind1L0T for String {
12	type Output<'a> = String;
13}
14
15impl<'b> Semigroup<'b> for String {
16	/// # Examples
17	///
18	/// ```rust
19	/// use fp_library::{brands::RcFnBrand, functions::append};
20	/// use std::rc::Rc;
21	///
22	/// assert_eq!(
23	///     append::<RcFnBrand, String>("Hello, ".to_string())("World!".to_string()),
24	///     "Hello, World!"
25	/// );
26	/// ```
27	fn append<'a, ClonableFnBrand: 'a + 'b + ClonableFn>(
28		a: Self
29	) -> ApplyFn<'a, ClonableFnBrand, Self, Self>
30	where
31		Self: Sized,
32		'b: 'a,
33	{
34		ClonableFnBrand::new(move |b: Self| a.to_owned() + &b)
35	}
36}
37
38impl Semigroup1L0T for String {}
39
40impl<'a> Monoid<'a> for String {
41	/// # Examples
42	///
43	/// ```rust
44	/// use fp_library::functions::empty;
45	///
46	/// assert_eq!(
47	///     empty::<String>(),
48	///     ""
49	/// );
50	/// ```
51	fn empty() -> Self {
52		Self::default()
53	}
54}
55
56impl Monoid1L0T for String {}