This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from ctypes import CDLL, c_void_p, byref | |
| from ctypes.util import find_library | |
| # The following code fails on ubuntu 18.04, but succeeds on 14.04 | |
| lib = CDLL(find_library('guestlib')) | |
| handle = c_void_p() | |
| ret = lib.VMGuestLib_OpenHandle(byref(handle)) | |
| if ret != 0: | |
| raise RuntimeError("failed to get handle") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object ReaderMonad extends App { | |
| case class Reader[-E, +A](run: E => A) { | |
| def map[B](fn: A => B): Reader[E, B] = | |
| dimap((e: E) => e)(fn) | |
| def contramap[E0](fn: E0 => E): Reader[E0, A] = | |
| dimap(fn)(a => a) | |
| def dimap[E0, B](f: E0 => E)(g: A => B): Reader[E0, B] = | |
| Reader(e0 => g(run(f(e0)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| import random | |
| import parsec as p | |
| import dataclasses as dc | |
| ########### | |
| ### AST ### | |
| ########### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import functools | |
| import typing as ty | |
| from dataclasses import dataclass | |
| A = ty.TypeVar("A") | |
| B = ty.TypeVar("B") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import dataclasses as dc | |
| import typing as ty | |
| import inspect | |
| import functools | |
| S = ty.TypeVar("S") | |
| A = ty.TypeVar("A") | |
| B = ty.TypeVar("B") | |
| @dc.dataclass(frozen=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun <A, B, R> curry2(fn: (A, B) -> R): (A) -> (B) -> R = { a -> { b -> fn(a, b) } } | |
| fun <A, B, C, R> curry3(fn: (A, B, C) -> R): (A) -> (B) -> (C) -> R = { a -> { b -> { c -> fn(a, b, c) } } } | |
| fun <A, B> const(a: A, b: B): A = a | |
| fun <A, B, C> flip(fn: (A, B) -> C): (B, A) -> C = { b, a -> fn(a, b) } | |
| infix fun <A, B> Parser<A>.pairing(p: Parser<B>): Parser<Pair<A, B>> = | |
| Parser.liftA2(curry2(::Pair), this, p) | |
| infix fun <A> Parser<A>.or(p: Parser<A>): Parser<A> = | |
| this alt p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Collection; | |
| import java.util.List; | |
| import java.util.function.Function; | |
| public interface Fold<Acc, From, To> { | |
| Monoid<Acc> ev(); | |
| Acc quantify(From x); | |
| To combine(Acc acc); | |
| default To fold(Collection<From> xs) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.function.BiFunction; | |
| import java.util.function.Supplier; | |
| public interface Monoid<T> extends Semigroup<T> { | |
| T empty(); | |
| static <T> Monoid<T> of(Supplier<T> v, BiFunction<T, T, T> app) { | |
| return new Monoid<>() { | |
| @Override | |
| public T empty() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Collection; | |
| import java.util.function.BiFunction; | |
| import java.util.function.Function; | |
| import java.util.function.Supplier; | |
| public interface Fold<Acc, From, To> { | |
| Acc empty(); | |
| Acc step(Acc acc, From x); | |
| To combine(Acc acc); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import static org.assertj.core.api.Assertions.assertThat; | |
| import java.util.function.Function; | |
| import org.junit.Test; | |
| import io.atlassian.fugue.Either; | |
| public class ChainTest { | |
| static class Context<T, Status extends Enum<Status>> { |