email rss
resiter v0.4.0
Oct 25, 2019
2 minutes read

This is a short release announcement. resiter was released in version v0.4.0 earlier this day.

v0.4.0

The changelog is rather minimal, as only one feature was added to the library: The iterator extension map_inner_ok_or_else(). But lets start at the beginning.

If you have an Result<Option<T>, E>>, you often want to transform this structure in the following way:

  1. If there is an Err(_), keep it
  2. If there is an Ok(Some(_)), unwrap the Some(_)
  3. If there is an Ok(None) you want to get a nice Err(_) for this.

So you often end up with code like this:

object.and_then(|o| o.ok_or_else(|| do_something()))

This is not complicated and even convenient. But if you need to do this all the time, it gets tiresome and is of course not easy to read if it appears all the time. It is way less complicated, though, to just do

object.inner_ok_or_else(|| do_something())

Easy, right?

Now, if you have an Iterator<Item = Result<Option<T>, E>>, you need to apply this function to each element:

iter.map(|e| e.inner_ok_or_else(|| do_something())).collect::<Result<_>>()

for example. Ugly to read, right? So that’s what the new feature does, it helps you doing that without writing the above ugly thing:

iter.map_inner_ok_or_else(|| do_something()).collect::<Result<_>>()

v0.3.0

(There was no post about 0.3.0, so here goes a short note)

Before that there was a v0.3.0 release, which was entirely written by Dawid. Thank you a lot for that! The changelog for that is a lot longer than the v0.4.0 changelog, it ships a lot of awesome features, make sure to check it out!


Back to posts