- Make sure your rust application uses https://github.com/gnzlbg/jemallocator as the global memory allocator (when in doubt, grep
jemallocatorin yourCargo.lock). - Install
jemalloc(we'll only needjeprof),dot,ps2pdfandlibunwindon your system. Enable jemallocator'sprofilingfeature (ifjemallocatoris an indirect dependency, one trick to do is to add a dependencyjemallocator = { version = "*", features = ["profiling"] }to your app and let cargo select the||of features for you). export _RJEM_MALLOC_CONF=prof:true,lg_prof_interval:32,lg_prof_sample:19.lg_prof_intervalsets how often profile dump should be written to disk measured in allocated bytes. The value is passed as a power of two, which is 2^32 in our case, i.e. every 4 GiB of allocations of long-lived objects (see https://github.com/jemalloc/jemalloc/wiki/Use-Case%3A-Heap-Profiling).lg_prof_sample:19tells jemalloc to take a profiling sample every 2^19 = 512 KiB.- Running your binary should produce a bun
| import cats.Monad | |
| import cats.effect.concurrent.{Ref, Semaphore} | |
| import cats.effect.{Concurrent, Resource} | |
| import cats.implicits._ | |
| import fs2.{Pipe, Stream} | |
| import fs2.concurrent.{NoneTerminatedQueue, Queue} | |
| /** Represents the ability to enqueue keyed items into a stream of queues that emits homogenous keyed streams. | |
| * |
This note outlines a principled way to meta-programming in Scala. It tries to combine the best ideas from LMS and Scala macros in a minimalistic design.
-
LMS: Types matter. Inputs, outputs and transformations should all be statically typed.
-
Macros: Quotations are ultimately more easy to deal with than implicit-based type-lifting
-
LMS: Some of the most interesting and powerful applications of meta-programming
| object Example { | |
| import cats._, implicits._ | |
| import cats.effect._ | |
| import fs2._ | |
| import scala.concurrent.ExecutionContext | |
| // start N streams concurrently, and stream their results in order | |
| // e.g. download a file from a server in N parts concurrently, and stream it | |
| abstract class Channel[F[_], A] { |
Edit: This list is now maintained in the rust-anthology repo.
| # Download latest archlinux bootstrap package, see https://www.archlinux.org/download/ | |
| wget 'ftp://ftp.nluug.nl/pub/os/Linux/distr/archlinux/iso/latest/archlinux-bootstrap-*-x86_64.tar.gz' | |
| # Make sure you'll have enough entropy for pacman-key later. | |
| apt-get install haveged | |
| # Install the arch bootstrap image in a tmpfs. | |
| mount -t tmpfs none /mnt | |
| cd /mnt | |
| tar xvf ~/archlinux-bootstrap-*-x86_64.tar.gz --strip-components=1 |
Java 8 introduced lambdas to the Java language. While the design choices differ in many regards from Scala's functions, the underlying mechanics used to represent Java lambdas is flexible enough to be used as a target for the Scala compiler.
Java does not have canonical heirarchy of generic function types (ala scala.FunctionN), but instead allows a lambda to be used as a shorthand for an anonymous implementation of an Functional Interface
Here's an example of creating a predicate that closes over one value:
| // List comprehension in C++11 in form of SQL-like syntax | |
| // Example code from http://vitiy.info/cpp11-writing-list-comprehension-in-form-of-sql/ | |
| // Written by Victor Laskin (victor.laskin@gmail.com) | |
| #include <iostream> | |
| #include <functional> | |
| #include <vector> | |
| #include <future> | |
| #include <algorithm> | |
| using namespace std; |