prelude-ls icon indicating copy to clipboard operation
prelude-ls copied to clipboard

Nice to have functions

Open askucher opened this issue 10 years ago • 6 comments


# checking for null and undefined
const item =
  test |> maybe (.maybe-not-exists-prop)  |> maybe (.deeply-prop)

# return new object with additional properties
const item = 
   test |> extend (new-prop: 1, new-prop2: 2)



askucher avatar Jul 29 '14 00:07 askucher

LiveScript already has operators for those.

The first is covered by ?., or just ? for short.

item = test?maybe-not-exists-prop?deeply-prop

If you really want it as a function, use the bracketed operator-call shorthand:

item = test |> (?maybe-not-exists-prop) |> (?deeply-prop)

or even just

item = test |> (?maybe-not-exists-prop?deeply-prop)

The second is covered by combining ^^ cloneport and import (<<<):

item = ^^test <<< { new-prop1: 1, new-prop2 : 2 }

There's even the infix with operator as an alias for that combination, since it's so common:

item = test with new-prop1 : 1, new-prop2 : 2

As usual, you can make it a function if you want:

item = test |> (with new-prop1 : 1, new-prop2 : 2)

anko avatar Jul 30 '14 11:07 anko

Damn, This is beautiful. You are best language designers. guys!!!

askucher avatar Jul 31 '14 01:07 askucher

There are a lot of developers around me use coffeescript because it is popular. When I try to convince people that livescript is much much better I meet their mind barrier but be patient guys your star time come soon. I cannot use other languages. Livescript the best

askucher avatar Jul 31 '14 01:07 askucher

because it is popular

So true. Unfortunately.

Delapouite avatar Jul 31 '14 08:07 Delapouite

Happy to help. Praise belongs to who did the work.

I assume this issue can be closed now?

anko avatar Jul 31 '14 14:07 anko

^^ cloneport

cloneport is actually "with":

$ lsc -le "a with b"
NEWLINE:\n ID:a CLONEPORT:with ID:b NEWLINE:\n

vendethiel avatar Oct 24 '14 10:10 vendethiel