e.g. in Kotlin, when a function with only one parameter is accepted, in it's definition, the first parameter name can be omitted and instead it's named it implicitly:

strings.filter { it.length == 5 }.sortedBy { it }.map { it.toUpperCase() }
So there it's even part of the core language. In Nim it's only a part of certain stdlib templates, but it shows that there are other places, where such implicit things are used.

Also the it is part of the template's name(mapIt, applyIt, ...).

2017-11-11 22:58:48

@Araq Maybe you don't need flexibility but please imagine using a it-template inside of an it-template (e.g. an apply inside of an apply). Just like @olwi said, => is better and I think it should be brought to standard Nim.

People only mention two reasons to use it-templates, correct me if I'm wrong:

  • "shorter code" --- ok, but also less flexible (apply-in-apply) and less readable (a matter of taste, I admit)
  • "closures are inefficient" --- why not making them efficient somehow? Like inlining, let's say?

@doofenstein But it's optional (just like in, let's say, Scala). Why? Because of the higher-order-functions composition, which would make it (pun intended) ambiguous.

2017-11-11 23:59:36