F# Snippets
Recently added snippets
Convert booleans to bits using fold
@Samuel - saw your post and thought one part was similar to bit shifting I was playing with yesterday, so rewrote the FromBooleans function using a fold instead of ref cells. Probably not as readable as your version though :)
Posted: 4 days ago by Chris Ballard
Convert booleans to bits and back
Convert an array of booleans to an array of bytes with 8 booleans packed in one byte. The reverse operation from a byte array to a boolean array is also provided.
Posted: 4 days ago by Samuel Bosch
Decoder for Google API polylines
Full source code for my blog entry on this subject - http://chrsb.co/BNqAbM
Posted: 5 days ago by Chris Ballard
single-case DU with shadowed constructor
single-case DU with shadowed constructor for passing non-primitives around that are already validated.
Posted: 6 days ago by ImaginaryDevelopment.blogspot.com
Splitting a sequence based on separator condition
Whilst working on a google API wrapper, I came across the need to separate a sequence into sub-sequences based on a separator condition. This also led to a requirement for versions of takeWhile and skipWhile which also include the element which first breaks the condition predicate.
Posted: 6 days ago by Chris Ballard
tryGetDefault dictionary extension
Try get a value from a dictionary and return a default value when not found. I provided two version. Pick the one you like the most.
Posted: 6 days ago by Samuel Bosch
Popular snippets
A beautiful fixed-point finding function
We start with an initial value and then applying f repeatedly, until the value does not change anymore.
241 people like this
Posted: 3 years ago by Nick PalladinosThe Haskell const function
The const function is simple, but you can use it to make your code more legible. In this example we convert a unary function to a function of arity 2 (that ignores the second argument). Also by using the flip function from Haskell (which is equally easy to define) you can ignore the first argument.
99 people like this
Posted: 3 years ago by Alex MuscarFSX Structure
I use this basic template when writing .fsx files that I might want to compile. It adjusts the difference in command line/entrypoint handling between a script and a compiled assembly. This example shows the details for a WPF script — replace the #r's and/or remove the STAThread for a WinForms or Console script.
93 people like this
Posted: 3 years ago by Blake Coverett
Haskell function : iterate
Implements iterate function from Haskell's Prelude. The function generates an infinite sequence by applying a function to the initial value (first) and then to the result of previous application.
156 people like this
Posted: 3 years ago by Nick PalladinosImplementing active objects with a MailboxProcessor
Mailbox processors can easily be used to implement active objects. This example shows how to do that with a reusable wrapper type and minimal boilerplate code in the actual class definitions. Supports both asynchronous calls and synchronous calls. For the latter case, exceptions are automatically propagated back to the caller.
76 people like this
Posted: 3 years ago by Wolfgang MeyerAdapter pattern
Invoke the methods from incompatible types
92 people like this
Posted: 2 years ago by Tao Liu
Snippets by tags
View all..Snippets by authors
View all..Database contains 1402 snippets out of which 1062 are public.