Skip to content

Instantly share code, notes, and snippets.

View ksavelev's full-sized avatar

Konstantin Savelyev ksavelev

  • Danske Bank
  • Copenhagen
View GitHub Profile
@ksavelev
ksavelev / fp.md
Created June 14, 2011 20:40 — forked from igstan/fp.md
Patterns and idioms in functional languages

I'll throw my opinion in here, but take it with a pretty large grain of salt as I've done no professional development in a functional language yet. Just tinkering with (quite a few of) them in my spare time. Some of the patterns I spotted are irrespective of type systems (static, dynamic).

  • lists, sequences or similar primitives are ubiquitous
  • abstract away duplicate code using higher-order functions
  • no iteration constructs, recursion is the only way to traverse lists
  • watch out your recursion, be sure it's tail-recursive
  • abstract over this tail-recursive pattern with a higher-order function: foldLeft or foldRight. So, know your language's equivalent of foldLeft/foldRight and prefer these over explicit recursion.
  • abstract over folds in an even more general way and provide folding functions for arbitrary data structures, not just list, e.g., trees.
  • provide a few convenience higher-order functions (implementable using fold) like: map, filter, any/some, all/every, zip, `zipWith
@ksavelev
ksavelev / http_status_codes
Created December 22, 2011 12:14
Explain HTTP status code on the command line
# based on https://github.com/rspivak/httpcode/blob/master/src/httpcode/__init__.py
# http://ruslanspivak.com/2011/12/21/httpcode-explain-http-status-code-on-the-command-line/
# just put it into your Powershell profile and use like $http_status_code[405]
$http_status_codes = @{
100 = @('<Continue>', 'Request received, please continue');
101 = @('<Switching Protocols>',
'Switching to new protocol; obey Upgrade header');
200 = @('<OK>', 'Request fulfilled, document follows');
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Mike.Spikes.ConsoleShutdown
{
class Program
{
static void Main(string[] args)
{