FAQ Database Discussion Community


Idiomatic list construction

list,haskell,functional-programming,idiomatic
I'm very new to Haskell and functional programming in general, so I don't really know how to make this code idiomatic: type Coord = Double data Point = Point Coord Coord Coord deriving Show type Polyline = [Point] -- Add a point to a polyline addPoint :: Polyline -> Point...

Non-repetitive way of saying: access this object's member unless the object is null [duplicate]

c#,idiomatic,null-coalescing
This question already has an answer here: Safe Navigation Operator in C#? [duplicate] 4 answers Let's say I have a set of cars, where each car has a steering wheel. I'd like to write a line of code that looks for a car in the set and returns its...

Is there any implicit providing `some.long.expression.let(x => …)` syntax

scala,scalaz,idiomatic
For example I want to get x * (x - 1) in the end of my long expression without separating it into two lines and introducing unnecessary variables. I could achieve it with simple implicit: scala> implicit class Rich[T](x: T) { def let[U](f: T => U) = f(x)} defined class...

Scala: how to implement via function object parameters a generic flow where signatures differ?

java,scala,functional-programming,idiomatic
I am a Java programmer taking baby steps into Scala programming. I have defined a function similar to (which may be idiomatically wrong, I wouldn't know...): def someGenericAlgorithm(param1: String, param1: String, param3: String) = { val triedResult1 = someFunction(param1) triedResult1 match { case Success(result1) => val triedResult2 = someOtherFunction(param2) triedResult2...

Extracting multi-dimentsional arrays in Javascript/JQuery

javascript,jquery,multidimensional-array,highcharts,idiomatic
I'm extracting some data from an SQL source, which I can get into a javascript script as a simple array (shown grouped by dates) which consists of week no, task number and hours spent: mydata = [ // weekno, taskno, hours ["2014-14",160,37.5], ["2014-15",160,30], ["2014-15",243,7.5], ["2014-16",160,37.5], ["2014-17",0,7.5], ["2014-17",3,7.5], ["2014-17",321,22.5], ["2014-18",0,7.5], ["2014-18",321,30],...

Is there idiomatic scoped sematics in golang?

go,deferred,idiomatic,scoped-lock
I wonder if there is any idiomatic way to represent scoped sematics. By scoped I mean things like: scoped mutex (oneliner instead of explicit Lock + deffered Unlock), logging function (or any code block) entrance and exit, measuring execution time. Example code for first two bullets: package main import "log"...

Idiomatic way to communicate state from derived page in MVC?

asp.net-mvc,asp.net-mvc-4,layout,idiomatic
I have navbar elements in my _Layout.cshtml which depend on the controller being called. On a search page there will be no navigation but in order to keep the style of the site consistent the navbar itself will remain. I'm not sure what is the most accepted and idiomatic way...

What's the idiomatic way to generate a reordered array in Objective-C?

objective-c,arrays,idiomatic
I can come up with all sorts of ways to achieve this but I am looking for the most elegant, idiomatic way to do this in Ojective-C: I have an array of alphabetically sorted currency codes from [NSLocale ISOCurrencyCodes];. Now I want to generate a new array with the five...

Explicit type annotation for generic constructor of a generic type

generics,rust,idiomatic
I'm writing a Rust binding for a C library. It implements an entity that can be constructed from different source entities, possibly saving some references internally. I want the Rust type to enforce a safe ownership policy, thus the wrapper struct is generic, parameterized by the type of the stored...

Is recursion a smell (in idiomatic Clojure) because of of zippers and HOFs?

recursion,clojure,higher-order-functions,idiomatic,zipper
The classic book The Little Lisper (The Little Schemer) is founded on two big ideas You can solve most problems in a recursive way (instead of using loops) (assuming you have Tail Call Optimisation) Lisp is great because it is easy to implement in itself. Now one might think this...

Iterate over all pair combinations without repetition in Haskell

haskell,functional-programming,tuples,combinations,idiomatic
In haskell, given a list of elements, xs, the simplest way to iterate over all pair permutations with repetitions is: [(x,y) | x <- xs, y <- xs] I wish to be able to do the same, but only on combinations. If x and y were comparable, I could do...

Which is the more idiomatic method in ClojureScript for printing to the console?

console,clojurescript,idiomatic
I have two options for printing to the console in ClojureScript. Which is the more idiomatic? (.log js/console "Hello World!") or (enable-console-print!) (println "Hello world!") My question is: Which is the more idiomatic method in ClojureScript for printing to the console?...