noether icon indicating copy to clipboard operation
noether copied to clipboard

Try.* functions

Open sphaso opened this issue 5 years ago • 3 comments

PR #29 highlighted how there's a set of functions from Scala\Haskell that we haven't considered. In particular Try.map from Scala acts as a functor on Try objects, applying a function in case no exception was thrown.
Currently we have Either.try which maps a function application to an either, i.e., :ok if the function succeeded, :error if an exception was thrown.

A few questions from the top of my head:

  • do we need Try.map when the user could use the with construct? (or just map after the Either.try)
  • are there other functions outside of Either.try that we could implement?
  • would it make sense to treat Try as a separate module (i.e. not piggybacking on either)?

@paolosimone @neslinesli93 @cottinisimone

sphaso avatar Sep 24 '20 09:09 sphaso

Ehi @sphaso, How are you?

About this i think that even if with the with construct you can achieve this behavior this function (that i would add in a separate Try module) might add some extra sugar that might be useful. I would implement some functions like map, map_error and try (just catch the exception and returns something got from params wrapped in an error {:error, something})

cottinisimone avatar Dec 16 '24 13:12 cottinisimone

Hi @cottinisimone thanks for your feedback! if you want to work on this let me know, it would be great :)

sphaso avatar Dec 17 '24 10:12 sphaso

Ok, i'll find some free time to contribute in this!

cottinisimone avatar Dec 18 '24 10:12 cottinisimone