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 move |b| a.to_owned() + &b
24 }
25}
26
27impl Monoid for StringBrand {
28 /// # Examples
29 ///
30 /// ```rust
31 /// use fp_library::{brands::StringBrand, functions::empty};
32 ///
33 /// assert_eq!(
34 /// empty::<StringBrand>(),
35 /// ""
36 /// );
37 /// ```
38 fn empty() -> Apply<Self, ()> {
39 Apply::<Self, ()>::default()
40 }
41}