fp_library/types/
once_cell.rs1use crate::{
4 classes::{Once, once::ApplyOnce},
5 hkt::{Apply0L1T, Kind0L1T},
6};
7use std::cell::OnceCell;
8
9#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub struct OnceCellBrand;
11
12impl Kind0L1T for OnceCellBrand {
13 type Output<A> = OnceCell<A>;
14}
15
16impl Once for OnceCellBrand {
17 type Output<A> = Apply0L1T<Self, A>;
18
19 fn new<A>() -> ApplyOnce<Self, A> {
20 OnceCell::new()
21 }
22
23 fn get<A>(a: &ApplyOnce<Self, A>) -> Option<&A> {
24 OnceCell::get(a)
25 }
26
27 fn get_mut<A>(a: &mut ApplyOnce<Self, A>) -> Option<&mut A> {
28 OnceCell::get_mut(a)
29 }
30
31 fn set<A>(
32 a: &ApplyOnce<Self, A>,
33 value: A,
34 ) -> Result<(), A> {
35 OnceCell::set(a, value)
36 }
37
38 fn get_or_init<A, B: FnOnce() -> A>(
39 a: &ApplyOnce<Self, A>,
40 f: B,
41 ) -> &A {
42 OnceCell::get_or_init(a, f)
43 }
44
45 fn into_inner<A>(a: ApplyOnce<Self, A>) -> Option<A> {
46 OnceCell::into_inner(a)
47 }
48
49 fn take<A>(a: &mut ApplyOnce<Self, A>) -> Option<A> {
50 OnceCell::take(a)
51 }
52}