[][src]Trait kai::BoolMap

pub trait BoolMap {
    fn map<T>(self, value: T) -> Option<T>;
fn map_with<T, F>(self, f: F) -> Option<T>
    where
        F: FnMut() -> T
; }

Maps bools to Options in one line

Example

use kai::*;

let condition = true;

// Turn this:
let s = if condition {
    Some(String::new())
} else {
    None
};

// Into this:
let s = condition.map_with(String::new);

assert_eq!(Some(String::new()), s);

Required methods

fn map<T>(self, value: T) -> Option<T>

Map to an optional value

fn map_with<T, F>(self, f: F) -> Option<T> where
    F: FnMut() -> T, 

Map to an optional value using a function

Loading content...

Implementors

impl<B> BoolMap for B where
    B: Into<bool>, 
[src]

Loading content...