1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Applicative functor.
//! Allows application of a function in an Applicative context to a value in an Applicative context.
//!
//! # Examples
//!
//! ```
//! use rust2fun::prelude::*;
//!
//! # type CreditCardNumber = String;
//! # type Date = String;
//! # type Code = u16;
//! # type Error = u8;
//! #
//! # struct CreditCard {
//! # number: CreditCardNumber,
//! # expiration: Date,
//! # cvv: Code,
//! # }
//! #
//! # impl CreditCard {
//! # fn new(number: CreditCardNumber, expiration: Date, cvv: Code) -> Self {
//! # CreditCard {
//! # number,
//! # expiration,
//! # cvv,
//! # }
//! # }
//! # }
//! #
//! fn validate_number(number: CreditCardNumber) -> Result<CreditCardNumber, Error> {
//! unimplemented!("Validate credit card number")
//! }
//!
//! fn validate_expiration(date: Date) -> Result<Date, Error> {
//! unimplemented!("Validate credit card expiration date")
//! }
//!
//! fn validate_cvv(cvv: Code) -> Result<Code, Error> {
//! unimplemented!("Validate credit card cvv")
//! }
//!
//! fn validate_credit_card(
//! number: CreditCardNumber,
//! expiration: Date,
//! cvv: Code,
//! ) -> Result<CreditCard, Error> {
//! Result::pure(CreditCard::new)
//! .ap3(validate_number(number),
//! validate_expiration(expiration),
//! validate_cvv(cvv))
//! }
//! ```
use crateApply;
use cratePure;
/// Applicative functor. This is a stronger version of Apply that has pure.
/// See [the module level documentation](self) for more.