Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They're operators that cons an element on to a list. They're both defined on the List class, but differ in associativity because they start/end in a colon.

"a +: l" calls the +: method on l with a as its argument and returns a list with a added to the start, "l :+ b" calls the :+ method on l with b as its argument and returns a list with b added to the end. "a +: l :+ b" (parsed as "(a +: l) :+ b") therefore returns a copy of l with a added to the start and b added to the end.

This is user definable, you can make operators whichever way you like (and start them with : if you want them to be right associative).

It's very flexible and you do sort of get used to libraries using it, but I'm not entirely sure that getting used to something always means it's good.

(TBH though, I use the ternary operator constantly and think nothing of it.)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: