Skip to content

Instantly share code, notes, and snippets.

View dxtr's full-sized avatar

dxtr

  • Paf
  • Sweden
View GitHub Profile
@dxtr
dxtr / effectful-servant.md
Created October 10, 2024 19:00 — forked from ollimandoliini/effectful-servant.md
effectful ♥️ servant

effectful ♥️ servant

In the Haskell world effect systems are currently a big thing and one of the most popular libraries on that front is effectful. When it comes to libries for creating webservices, the most popular one at the time of writing this is probably servant.

The two libraries go very well together but it isn't exactly obvious how you can marry them up since there doesn't seem to exist any examples at the moment. That's why I decided to create one. I'll go through setting up a simple service line by line and at the end of post I'll post the whole example. So if you're just after some quick boilerplate you can scroll right to the end.

If you haven't already, create a new project using cabal init -i. Then let's add some dependencies to our cabal file. You can probably get away with loosening most of the constraints but with those the example is guaranteed to work on ghc-9.2.7.

IntegrationFlow privateFeedFlow = f -> f.handle(Tcp
.outboundGateway(
Tcp.netClient(privateFeed.getHostname(), (int) privateFeed.getPort())
.serializer(TcpCodecs.crlf())
.deserializer(TcpCodecs.lengthHeader1())
.id("privateFeed"))
.remoteTimeout(m -> 5000))
.transform(Transformers.objectToString())
.handle(System.out::println);

Keybase proof

I hereby claim:

  • I am dxtr on github.
  • I am dxtr (https://keybase.io/dxtr) on keybase.
  • I have a public key ASAy7h0QP0TcCsY-pPw5k5bHBdn2kW_ZZTJBYdo5RJUW1wo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am dxtr on github.
  • I am dxtr (https://keybase.io/dxtr) on keybase.
  • I have a public key whose fingerprint is B1BF 3F4B 30C2 DA00 8BEB 137F 8018 F380 D795 A951

To claim this, I am signing this object:

@dxtr
dxtr / Capfile
Created December 9, 2015 13:11 — forked from spalladino/Capfile
Hacking an erlang application deployment with Capistrano 3
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
namespace :deploy do
#lang racket
(define (string-empty? str)
(= (string-length str) 0))
(define (file-name-as-string fn)
(cond
((path? fn) (path->string fn))
((string? fn) fn)
(else (error "Unkonwn type!"))))
@dxtr
dxtr / keybase.md
Last active August 29, 2015 13:59

Keybase proof

I hereby claim:

  • I am dxtr on github.
  • I am dxtr (https://keybase.io/dxtr) on keybase.
  • I have a public key whose fingerprint is 97A0 CF43 6922 4351 DC3C 5A0B B00B 3118 0662 D334

To claim this, I am signing this object: