Adding Days to a Date but Excluding Weekends
using Fluent DateTime https://github.com/FluentDateTime/FluentDateTime var dateTime = DateTime.Now.AddBusinessDays(4);
using Fluent DateTime https://github.com/FluentDateTime/FluentDateTime var dateTime = DateTime.Now.AddBusinessDays(4);
This question has been answered for some time now, but I was quite surprised that most of the answers say what OCaml features are missing in F# – this is definitely good to know if you want to port existing OCaml programs to F# (which is probably the motivation of most of the referenced articles). … Read more
I think there must be a better way to find out that a file is not available than using a timeout. I’m not exactly sure, but is there some way to make it throw an exception if a file cannot be found? Then you could just wrap your async code inside try .. with and … Read more
This is F#’s embarrassing skeleton in the closet. Try this: > let mapPair f (x,y) = (f x, f y) val mapPair : f:(‘a -> ‘b) -> x:’a * y:’a -> ‘b * ‘b Fully generic! Clearly, function application and tuples work. Now try this: > let makeList a b = [a;b] val makeList : … Read more
you can also write something like this: let rec permutations list taken = seq { if Set.count taken = List.length list then yield [] else for l in list do if not (Set.contains l taken) then for perm in permutations list (Set.add l taken) do yield l::perm } The ‘list’ argument contains all the numbers … Read more
Here is the (non idiomatic) solution: type Mult = Mult with static member inline ($) (Mult, v1: ‘a list) = fun (v2: ‘b list) -> v1 |> List.collect (fun x -> v2 |> List.map (fun y -> (x, y))) : list<‘a * ‘b> static member inline ($) (Mult, v1:’a ) = fun (v2:’a) -> v1 … Read more
This is called a nonlinear pattern. There have been several threads on the haskell-cafe mailing list about this, not long ago. Here are two: http://www.mail-archive.com/haskell-cafe@haskell.org/msg59617.html http://www.mail-archive.com/haskell-cafe@haskell.org/msg62491.html Bottom line: it’s not impossible to implement, but was decided against for sake of simplicity. By the way, you do not need if or case to work around this; … Read more
I’ve just recently discovered the functional programming style […] Well, recently I was given a chance to give a talk on how to reduce software development efforts, and I wanted to introduce the concept of functional programming. If you’ve only just discovered functional programming, I do not recommend trying to speak authoritatively on the subject. … Read more
The Microsoft CLR has a 2GB maximum object size limit, even the 64 bit version. (I’m not sure whether this limit is also present in other implementations such as Mono.) The limitation applies to each single object — not the total size of all objects — which means that it’s relatively easy to workaround using … Read more
Reading that article I came up with an idea that doesn’t require a multimap. It handles colliding map keys by moving the colliding key forward by its prime value again and again until it reaches a key that isn’t in the map. Below primes is a map with keys of the next iterator value and … Read more