Tagged Questions
The functional-programming tag has no wiki summary.
3
votes
3answers
68 views
Functional way to write this code
I have a pan control that look like this:
Pretty standard Google Mapsish controls, IMO.
When the user clicks in the top 3rd of the control, it should pan up (deltaY = +1); right third means it ...
1
vote
0answers
33 views
Functionally retrieving rows from a database in Scala
Consider the following piece of code:
var result = List[Measurement]()
val dbResult = conn.createStatement.executeQuery(unsentMeasurements)
while(dbResult.next) {
result ::= ...
3
votes
0answers
25 views
Timeoutable computations module
Defines a simple module for timeoutable computations, with the ability to return
arbitrary intermediary results on timeout or the final value otherwise. It also
allows default return values.
The ...
0
votes
0answers
87 views
Is my project fully MVC (and how can I improve it)?
I recently ported a project I had going to MVC. This is my first time utilizing MVC and I was wondering if I have done it correctly and properly, or if I have some parts in places where they ...
1
vote
2answers
86 views
Multiple if conditons in scala using funcional programming
The following code has a lot of conditionals. I am trying to write
it in a functional programming way.
val basePrice = {
var b = 0.0
if (runtime > 120)
b += 1.5
if ((day == Sat) || (day ...
0
votes
1answer
98 views
Javascript: Replacing a for loop that iterates over an array with the functional programming equivalent
Player.prototype.d2 = function(ratingList, rdList) {
var tempSum = 0;
for (var i = 0; i < ratingList.length; i++) {
var tempE = this.e(ratingList[i], rdList[i]);
tempSum += ...
3
votes
2answers
230 views
Enclosing Circle Problem implementation in Haskell
I implemented the algorithm by Pr. Chrystal described here in Haskell so could someone please tell me: Do i have implemented this algorithm correctly?
Initial calling of findPoints takes the first and ...
1
vote
2answers
170 views
Scala mastermind solver, which is the most scala-ish
I am trying to express the classical TDD kata of mastermind in the most idiomatic scala I can. Here is a scalatest, test suite :
package eu.byjean.mastermind
import org.junit.runner.RunWith
import ...
7
votes
1answer
168 views
Deleting from Red Black Tree in F#
Yes I'm very slowly making my way through Purely Functional Data Structures. So I went through the section on Red Black Trees. What he presents is amazingly concise, except for the fact that he didn't ...
2
votes
2answers
212 views
Can my solution to TopCoder's BestApproximationDiv2 problem be any better?
Link to problem statement on TopCoder
import Data.Char
import Data.List
import Data.Maybe
showResult :: (Int, Int, Int) -> String
showResult (a, b, x) = show a ++ "/" ++ show b ++ " has "
...
3
votes
1answer
131 views
Most elegant approach to writing list renumbering function
I'm writing a function with the following signature:
(Ord a) => [a] -> [Int]
It's semantics is to find an order-preserving mapping from list of objects to list of Ints.
The version of mine:
...
6
votes
6answers
371 views
Is this good approach to use debug functions for implementing features?
Just thinking if using code like this
<?php
abstract class helper
{
private static $_cycles = array();
public static function isOdd($v)
{
return (0 == ($v % 2)) ? false: ...
4
votes
1answer
194 views
Can anyone offer tips on making code more performant and more functional
The following block of code needs to be as fast as possible as it likely to be called many 1000s of times in a run. I am also conscious that my thinking style is leaning towards a more procedural ...
4
votes
3answers
275 views
Can this code be made better it's about generating permutations and combinations?
using System;
//using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace Combinatorics
{
public class Permutation
{
private int[] data = null;
private int ...
8
votes
1answer
230 views
Converting simple markup to HTML
This is going to be rather long and generic, so apologies in advance.
I've been reading a lot about Haskell lately, but I've never really programmed anything with it beyond simple experiments in ...