Skip to content

Instantly share code, notes, and snippets.

View LittleHelicase's full-sized avatar

Maximilian Klein LittleHelicase

  • Freiheit.com
  • Hamburg, Germany
View GitHub Profile
// data from washington post
const electionData = require('./election_2020_06_11_19_25.json');
const benfordslaw = require('benfordslaw');
// console.log(electionData);
function traverse(o,func) {
for (var i in o) {
func.apply(this,[i,o[i]]);
@LittleHelicase
LittleHelicase / # maven - 2018-04-22_16-53-08.txt
Created April 22, 2018 15:08
maven on macOS 10.13.4 - Homebrew build logs
Homebrew build logs for maven on macOS 10.13.4
Build date: 2018-04-22 16:53:08
fun Int?.toString() {
return "42"
}
fun Any?.toString() {
if (this == null) return "null"
return toString()
}
fun main(args : Array<String>) {
@LittleHelicase
LittleHelicase / download.js
Created January 11, 2018 21:35
Download all the files via javascript
// download files via predicate function. Simply paste this into the developer console on a site to download files. It will download all of them at once!
function downloadAllFiles(predicate) {
var files = Array.prototype.slice.call(document.getElementsByTagName("a"), 0).filter((tag) => predicate(tag.href)).map((t) => t.href)
files.forEach((p) => {
var clickEvent = document.createEvent("MouseEvent")
clickEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
var downloadButton = document.createElement("a")
downloadButton.href = p

Defining data structures in data-flow diagrams

We have seen, how we can define functions in data flow diagrams, but can we go further and define complex data structures using only the essential language elements of data-flow diagrams. Well as it turns out: yes, you can define algebraic data types in a day to day data-flow diagram and I want to show you how it is done.

But first a note on algebraic data types (ADT). If you don't know what those are, don't feel bad, they are rather simple. I will first show you how we define ADTs and what their benefits are, before I will introduce them into data-flow diagrams. If this seems rather odd, why would anybody want to do this, I can tell you, that it taught me a lot about the structure of data and how they work hand in hand with functions. I hope to also discuss how to create a powerful meta-language and the requirements to create those are so fundamental, that they apply to every language even our data-flow language.

So let's start with a simple definition of

Functions are data-flow time machines

Today data-flow diagrams are something every CS student and programmer has seen. It is a nice way of visualizing the general flow of data through an application. But it is rarely more than that. A few reasons for this might be an inconvenience in displaying details. They tend to get big!

Another problem is the rather limited language which is incapable of describing some fundamental ideas of CS like lambda functions. Would you know how to draw a lambda function in a data-flow diagram? If you ever heard of string diagrams, you might be able to do so, but most programmers wouldn't recognize them.

I myself adore data-flow diagrams and I'm fascinated by what you can do with them even in an functional setting. That's why I want to show you, how you can build lambda functions in a data-flow diagram in a functional way and what this has to do with time machines. But first lets start with some simple examples to get used to functional data-flow diagrams. Here we have a rat

// After
// Hutton, Graham. "A tutorial on the universality and expressiveness of fold." Journal of Functional Programming 9.04 (1999): 355-372.
// Lodash has no currying making it necessary to call a few partials. Fold is reduce in lodash and the order of
// the arguments is different. _.reduce(data, fn, initial) = fold(fn, inital, data)
var _ = require('lodash')
var ack = _.partial(
_.reduce,
_,
@LittleHelicase
LittleHelicase / index.html
Created November 7, 2014 11:08
Stack Sentence Beispiel // source http://jsbin.com/votehocalu
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Stack Sentence Beispiel</title>
<!-- der Stack wird über die ArrayList implementiert -->
<script src="http://jsbin.com/cuqure.js"></script>
<!-- Implementierung des Stacks als ArrayStack -->
<script src="http://jsbin.com/zucuze.js"></script>
</head>
@LittleHelicase
LittleHelicase / index.html
Created November 7, 2014 11:05
Rotieren mit ADTs // source http://jsbin.com/qotaka
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rotieren mit ADTs</title>
<!-- ADT Liste implementiert als ArrayList -->
<script src="http://jsbin.com/cuqure.js"></script>
<!-- ADT Liste implementiert als LinkedList -->
<script src="http://jsbin.com/wowobu.js"></script>
<!-- ADT Liste Hilfsfunktionen. Exportiert
@LittleHelicase
LittleHelicase / index.html
Created November 7, 2014 11:04
SubList mit ADTs // source http://jsbin.com/detaya
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>SubList mit ADTs</title>
<!-- ADT Liste implementiert als ArrayList -->
<script src="http://jsbin.com/cuqure.js"></script>
<!-- ADT Liste implementiert als LinkedList -->
<script src="http://jsbin.com/wowobu.js"></script>
<!-- ADT Liste Hilfsfunktionen. Exportiert