Pick last item from list in Powershell
You can use Select-Object -Last 1 at the end of that pipeline.
You can use Select-Object -Last 1 at the end of that pipeline.
>>> xs = list(range(165)) >>> xs[0::10] [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160] Note that this is around 100 times faster than looping and checking a modulus for each element: $ python -m timeit -s “xs = list(range(1000))” “[x for i, x in enumerate(xs) if … Read more
fun foo(vararg strings: String) { /*…*/ } Using foo(strings = arrayOf(“a”, “b”, “c”)) val list: MutableList<String> = listOf(“a”, “b”, “c”) as MutableList<String> foo(strings = list.map { it }.toTypedArray()) Named arguments are not allowed for non-Kotlin functions (*.java) So, in this case you should replace: From: strings = list.map { it }.toTypedArray() To: *list.map { it … Read more
You could do this using JSTL tags, but the result is not optimal: <%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%> <html> <body> <jsp:useBean id=”numbers” class=”java.util.HashSet” scope=”request”> <% numbers.add(“one”); numbers.add(“two”); numbers.add(“three”); %> </jsp:useBean> <c:forEach items=”${numbers}” var=”value”> <c:if test=”${value == ‘two’}”> <c:set var=”found” value=”true” scope=”request” /> </c:if> </c:forEach> ${found} </body> </html> A better way would be to use a custom … Read more
First of all, new List() won’t work, since the List class is abstract. The other two options are defined as follows in the List object: override def empty[A]: List[A] = Nil override def apply[A](xs: A*): List[A] = xs.toList I.e., they’re essentially equivalent, so it’s mostly a matter of style. I prefer to use empty because … Read more
Elm added arrays in 0.12.1, and the implementation was massively overhauled in 0.19 to improve correctness and performance. import Array myArray = Array.fromList [1..5] myItem = Array.get 2 myArray Arrays are zero-indexed. Negative indices are not supported currently (bummer, I know). Note that myItem : Maybe Int. Elm does everything it can to avoid runtime … Read more
The key in List<T>.slice function is the .toList() at the end, which will create a new List with the elements, using a shallow element copy. For summary: .slice() will create a new List with the shallow copy of the subset of elements; if the original list contains objects, changes to values within the objects will … Read more
I want to propose a lazier version of merge: merge [] ys = ys merge (x:xs) ys = x:merge ys xs For one example use case you can check a recent SO question about lazy generation of combinations. The version in the accepted answer is unnecessarily strict in the second argument and that’s what is … Read more
The most obvious difference is that take() can only use elements at the beginning, you can combine it with skip() like list.skip(3).take(5) to get similar behavior though. list.take() is lazy evaluated which works nice with functional style programming and might be more efficient if the elements aren’t actually iterated over later. list.take() also is tolerant … Read more