Closed plexigras closed 6 years ago
Hm. The behavior you describe here would probably not work out as written. It would need to be a placeholder arg:
'use @oigroup/lightscript with placeholderArgs'
x~(-> _)
Aside from that, the tilde call syntax is specifically written to disallow arbitrary expressions on the RHS. I shall have to ask @rattrayalex why it is that way. There might be some reason I'm not aware of.
Another question: what do you see as the value and/or win here? Do you have any particular use cases in mind?
you are right about it probably not working it would have to be something like x~(->y)()
because you can't do x~y
but have to do x~y()
to why i think when it would be usefull for example when you want to do a lodash less mapvalues you could do something like this
obj
~something()
~something()
~something()
~(x ->
Object.keys(x).reduce((acc,key) ->
acc[key] = x[val] + 1
acc
, {})
)()
~something()
~something()
~something()
Hmm. That seems a little ugly to me but I do see where it's coming from, and I can't presently think of a reason it should be illegal... I don't remember why I made it that way to begin with, other than generally thinking it'd be ridiculous/unreadable (which, looking at @plexigras 's example, would be an exaggeration).
So I don't think I'd be opposed to adding this feature.
I will point out that this is potentially a use case for the pipe operator, which is now on the JS standards track. In fact,
x~(-> stuff)!
is actually just
x |> -> stuff
I also think the pipe operator reduces a little bit of ugliness from the syntax, as it doesn't require the !
or ()
.
'use @oigroup/lightscript with noEnforcedSubscriptIndentation`
obj
~something()
~something()
~something()
|> x ->
Object.keys(x).reduce((acc,key) ->
acc[key] = x[val] + 1
acc
, {})
~something()
~something()
~something()
Incidentally, this is also a case study in why noEnforcedSubscriptIndentation
is a good idea. Without it:
obj
~x()
|> x -> x
~deepIndent()
|> x -> x
~deeperIndent()
x~(->y)
would be behave like(->y)(x)
and be transformed to(function() { return y; })(x);