Skip to content

Commit

Permalink
Include and_then for HeaderValue
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrw committed Jul 20, 2024
1 parent 42d49fa commit 9677461
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion fitsio/src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ where
self.comment.as_ref()
}

/// Map the _value_ of a `HeaderValue` to another form
/// Map the _value_ of a [`HeaderValue`] to another form
pub fn map<U, F>(self, f: F) -> HeaderValue<U>
where
F: FnOnce(T) -> U,
Expand All @@ -69,6 +69,20 @@ where
comment: self.comment,
}
}

/// Monadic "bind" for [`HeaderValue`]
pub fn and_then<U, F>(self, f: F) -> Result<HeaderValue<U>>
where
F: FnOnce(T) -> Result<U>,
{
match f(self.value) {
Ok(value) => Ok(HeaderValue {
value,
comment: self.comment,
}),
Err(e) => Err(e),
}
}
}

/**
Expand Down

0 comments on commit 9677461

Please sign in to comment.