-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change block to Proc #25
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Crystal a Block is like a Proc, but with a simpler syntax.
Why not allow both ?
Edit : sorry, I've read the reason.
Maybe there is a way to have both worlds. I will try myself today.
I tried and got this :
And for Crystal 0.28
Can you give me your errors ? |
I implement following code : class Left(E) < Either(E, Nil)
def fmap(&block : T -> U) forall T, U
self
end
end This code was implemented for the purpose of enabling execution of the same block with # a is Left(String) or Right(Int32)
a.fmap {|x| x + 1} But, if |
I asked Forum whether Crystal can infer |
Got it ! I opened an issue : #26 |
Contents of change
Changed following methods which received
&block
to receiveProc
.value_or
fmap
bind
map_or
Reason
In the current code, following code can not run correctly:
The cause lies with Crystal compiler can't infer function type(compiler can't infer
T
of&block : T -> U
).So instead of receiving a
&block
, change it to receive aProc
.As a result,
value_or(&block : ->U)
was deleted because it became impossible to overload.