Controlling effects in Java via capabilities. Early sketch.
class Main {
static void main(System system) {
byte[] bytes = loadFile(system.getFileSystem());
function fib(n) { | |
if(n < 2) return n; | |
return fib(n - 1) + fib(n - 2); | |
} | |
async function afib(n) { | |
if(n < 2) return n; | |
return await afib(n - 1) + await afib(n - 2); | |
} |
async function mapA(array, f) { | |
let result = []; | |
for(let i = 0; i < array.length; i++) { | |
result.push(await f(array[i])); | |
} | |
return result; | |
} | |
function map(array, f) { | |
let result = []; |
case class Location(file : String, line : Int, column : Int) { | |
override def toString = "_" | |
def toSuffix = "in " + file + " " + toShortString | |
def toShortString = "at line " + line + ", column " + column | |
} | |
case class Binding(at : Location, name : String, scheme : Option[Scheme], value : Term) | |
sealed abstract class TopBlock { | |
def name : String |
class Decoder { | |
constructor(dataView, options) { | |
options = options || {}; | |
this._dataView = dataView; | |
this._offset = 0; | |
this._staticDictionary = options.staticDictionary || []; | |
this._textDecoder = new TextDecoder('utf-8'); | |
if( |
type Functor[T[_]] { | |
map[A, B](x : T[A], f : A -> B) : T[B]; | |
} | |
type Monad[T[_]](functor : Functor[T]) { | |
flatten[A](x : T[T[A]]) : T[A]; | |
pure[A](value : A) : T[A]; | |
flatMap[A, B](x : T[A], f : A -> T[B]) : T[B] = | |
flatten(functor.map(x, f)) | |
} |
serversText <- File.readText "../../servers.txt" | |
servers = String.lines serversText | |
|> List.filter (x -> x != "") | |
hostTask = host -> | |
Ssh.do {user: "root", host: host} ( | |
result <- Process.shell {command: "hostname"}, | |
Task.of {name: String.trim result.out, host: host} | |
) |
html <- Http.fetchJson {url: "https://reqres.in/api/users?page=2"} | |
people : List {id: Int, "first_name": String, "last_name": String, avatar: String} = | |
Json.toAny html.data | |
htmlImage = url -> Html.tag "img" [Html.attribute "src" url] | |
peopleWithImages = people |> List.map ( | |
p -> {image: htmlImage p.avatar, name: p."first_name" + " " + p."last_name"} | |
) |
// WIP, untested attachable. A sort of generalized loader that should support infinite scroll and more. | |
// Example: | |
// val requester = Requester(this, Signal(1)) { (old, pageNumber) => | |
// fetchPage(pageNumber).map(_ ++ old.toList.flatten) | |
// } | |
// Later, request page 2: | |
// requester.request(2) | |
import com.github.ahnfelt.react4s.Loader.{Loaded, Loading, Result, Error} |
;;;;;;;;;; | |
; Prelude | |
;;;;;;;;;; | |
if := { | |
|True body _| body() | |
|False _ body| body() | |
} | |
when := { |