Refactor using `NonEmpty::try_map`

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-12-12 15:10:06 +01:00
parent f90f714fcf
commit 909b99bb7c
No known key found for this signature in database
3 changed files with 4 additions and 16 deletions

View File

@ -396,7 +396,7 @@ impl<'a> Issues<'a> {
tx.tag(tags.to_owned(), []); tx.tag(tags.to_owned(), []);
})?; })?;
// Just a sanity check that our clock is advancing as expected. // Just a sanity check that our clock is advancing as expected.
assert_eq!(clock.get(), 2); debug_assert_eq!(clock.get(), 2);
Ok(IssueMut { Ok(IssueMut {
id, id,

View File

@ -769,7 +769,7 @@ impl<'a> Patches<'a> {
tx.tag(tags.to_owned(), []); tx.tag(tags.to_owned(), []);
})?; })?;
// Just a sanity check that our clock is advancing as expected. // Just a sanity check that our clock is advancing as expected.
assert_eq!(clock.get(), 2); debug_assert_eq!(clock.get(), 2);
Ok(PatchMut::new(id, patch, clock, self)) Ok(PatchMut::new(id, patch, clock, self))
} }

View File

@ -104,13 +104,7 @@ where
actions: impl Into<NonEmpty<T::Action>>, actions: impl Into<NonEmpty<T::Action>>,
signer: &G, signer: &G,
) -> Result<CollaborativeObject, Error> { ) -> Result<CollaborativeObject, Error> {
let changes = actions let changes = actions.into().try_map(|e| encoding::encode(&e))?;
.into()
.iter()
.map(encoding::encode)
.collect::<Result<Vec<_>, _>>()?
.try_into()
.expect("the collection is always non-empty");
cob::update( cob::update(
self.raw, self.raw,
@ -135,13 +129,7 @@ where
actions: impl Into<NonEmpty<T::Action>>, actions: impl Into<NonEmpty<T::Action>>,
signer: &G, signer: &G,
) -> Result<(ObjectId, T, Lamport), Error> { ) -> Result<(ObjectId, T, Lamport), Error> {
let contents = actions let contents = actions.into().try_map(|e| encoding::encode(&e))?;
.into()
.iter()
.map(encoding::encode)
.collect::<Result<Vec<_>, _>>()?
.try_into()
.expect("the collection is always non-empty");
let cob = cob::create( let cob = cob::create(
self.raw, self.raw,
signer, signer,