fp_library/types/string.rs
1//! Implementations for [`String`].
2
3use crate::{
4 hkt::{Apply, Brand0, Kind0},
5 impl_brand,
6 typeclasses::{Monoid, Semigroup},
7};
8
9impl_brand!(StringBrand, String, Kind0, Brand0, ());
10
11impl Semigroup for StringBrand {
12 /// # Examples
13 ///
14 /// ```rust
15 /// use fp_library::{brands::StringBrand, functions::append};
16 ///
17 /// assert_eq!(
18 /// append::<StringBrand>("Hello, ".to_string())("World!".to_string()),
19 /// "Hello, World!"
20 /// );
21 /// ```
22 fn append(a: Apply<Self, ()>) -> impl Fn(Apply<Self, ()>) -> Apply<Self, ()>
23 where
24 Apply<Self, ()>: Clone,
25 {
26 move |b| a.to_owned() + &b
27 }
28}
29
30impl Monoid for StringBrand {
31 /// # Examples
32 ///
33 /// ```rust
34 /// use fp_library::{brands::StringBrand, functions::empty};
35 ///
36 /// assert_eq!(
37 /// empty::<StringBrand>(),
38 /// ""
39 /// );
40 /// ```
41 fn empty() -> Apply<Self, ()> {
42 Apply::<Self, ()>::default()
43 }
44}