Go that looks a little bit like Elm

Hi folks,

TLDR; scion-tools

Thought I would share a package I have been working on regarding functional programming in Go directly inspired by Elm.

I was missing some of the comforts I get from functional programming in the work I’m currently doing in Go so I set out to port over some of the data structures from elm/core.

It started with the Dict package, which is an immutable and persistent RBT, and quickly escalated to basically porting over most of the other packages.

It’s been fairly wonderful to chop and change between the idiomatic patterns that I love about Go and the expressiveness of functional programming that I’m used to.

Basic examples:

// Dct
Get(1, Singleton(1, "one")) // Just "one"

// List
Foldl(Cons,Empty[int](), [1,2,3]) // [3,2,1]

// Maybe
Map(Sqrt,(Just[Int]{9})) // Just 3

// String
DropLeft(2,"The Lone Gunmen") // "e Lone Gunmen"

You get the idea.

Much like the Elm kernel code the functions internally have been written with Tail-Call optimization in mind are immutable and persistant.

The package is called scion-tools and it’s still missing a lot of functions but I’m adding new ones all the time.

Thanks for reading!

1 Like