fp_library/types/
string.rs

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