tried to touch a #rust codebase again
-
tried to touch a #rust codebase again
no idea why I did that
what do you mean Option and Result and so on are monads but you can't just lift functions?
then why are they monads??
closest thing you get is `Option.zip_with` but it's Option-only and nightly-only
I'd have thought that moving fast and breaking compat literally every release would mean it wouldn't be literal decades behind -
tried to touch a #rust codebase again
no idea why I did that
what do you mean Option and Result and so on are monads but you can't just lift functions?
then why are they monads??
closest thing you get is `Option.zip_with` but it's Option-only and nightly-only
I'd have thought that moving fast and breaking compat literally every release would mean it wouldn't be literal decades behind@toast@donotsta.re i don't think many people see Option and Result as a Monad, not least because they (and i) have no clue what a monad is. (and tbh i'm not keen on finding out either)
-
@toast@donotsta.re i don't think many people see Option and Result as a Monad, not least because they (and i) have no clue what a monad is. (and tbh i'm not keen on finding out either)
@Johann150 they literally are monads! just… poorly implemented ones -
@Johann150 they literally are monads! just… poorly implemented ones
@toast@donotsta.re as i said, i don't think many rust programmers know what that is.
what are you trying to do anyway? -
@toast@donotsta.re as i said, i don't think many rust programmers know what that is.
what are you trying to do anyway?@Johann150@genau.qwertqwefsday.eu I have an
Option<a>
and I want to call afn(a) -> b
on it.
If theOption<a>
is None, the result should be none.
The operation of taking anfn(a)
and making it work on anOption<a>
is called a "monadic lift", and it's the whole purpose of having this kind of "wrapper type" to begin with, it's meant to be one of the most basic operations.
What I'm having to do is a.and_then
with an extra wrapper lambda which actually returns anOption
anyway (rendering the point of it kind of moot) -
@Johann150@genau.qwertqwefsday.eu I have an
Option<a>
and I want to call afn(a) -> b
on it.
If theOption<a>
is None, the result should be none.
The operation of taking anfn(a)
and making it work on anOption<a>
is called a "monadic lift", and it's the whole purpose of having this kind of "wrapper type" to begin with, it's meant to be one of the most basic operations.
What I'm having to do is a.and_then
with an extra wrapper lambda which actually returns anOption
anyway (rendering the point of it kind of moot)@toast@donotsta.re so what you want to do is modify the value inside the Option? have you tried using
map
? -
@toast@donotsta.re so what you want to do is modify the value inside the Option? have you tried using
map
?@Johann150 I'm just not happy that a basic operation (monadic lifting) requires going through "bonus steps", essentially -
@Johann150 I'm just not happy that a basic operation (monadic lifting) requires going through "bonus steps", essentially@Johann150 (thank you though, it's slightly nicer than going through and_then)
-
@Johann150 (thank you though, it's slightly nicer than going through and_then)
@toast@donotsta.re in my experience option and result have lots of functions that do similar things so its a bit confusing. sometimes i ended up searching for the call signature instead of the name to find what i wanted