Skip to content

Instantly share code, notes, and snippets.

View no-longer-on-githu-b's full-sized avatar

no longer on github no-longer-on-githu-b

View GitHub Profile
def abs(x: Number)(ensure out >= 0): Real =
x
|> non-zero-parts()
|> map(fn(x) => x ^ 2)
|> sum()
|> sqrt()
specialize def abs(x: Real): Real =
if x < 0 { -x } else { x }
def abs(x: Number)(ensure out >= 0): Real =
x
|> non-zero-parts()
|> map(fn(x) => x ^ 2)
|> sum()
|> sqrt()
specialize def abs(x: Real): Real =
if x < 0 { -x } else { x }
print "gist not found";
$1 == "File" && $2 ~ /helloworld\// {
print "\033[1;33m" $0 "\033[0m";
next;
}
{ print }
@no-longer-on-githu-b
no-longer-on-githu-b / gist:e1d8079e6b1b09d5e103
Created February 15, 2015 00:06
Optimal struct layout calculator.
#include <algorithm>
#include <cstddef>
#include <cmath>
#include <iostream>
#include <unordered_set>
#include <vector>
struct field {
std::size_t size;
std::size_t alignment;
import invalid._
sealed abstract class UserValidationError
case object FirstNameEmpty extends UserValidationError
case object LastNameEmpty extends UserValidationError
def createUser(saveUser: User => UserID)(firstName: String, lastName: String) =
validate(
firstName.isEmpty -> FirstNameEmpty,
lastName.isEmpty -> LastNameEmpty
def saveUser(ds: DataSource)(user: User): UserID = {
// blabla
}
abstract class UserValidationError
case object FirstNameEmpty extends UserValidationError
case object LastNameEmpty extends UserValidationError
def createUser(saveUser: User => UserID)(firstName: String, lastName: String): ValidationNel[UserValidationError, UserID] = {
def validateFirstName(name: String) = if (name.isEmpty) FirstNameEmpty.fail else name.success
def saveUser(ds: DataSource)(user: User): UserID = {
// blabla
}
abstract class UserValidationError
case object FirstNameEmpty extends UserValidationError
case object LastNameEmpty extends UserValidationError
def createUser(saveUser: User => UserID)(firstName: String, lastName: String): ValidationNel[UserValidationError, UserID] = {
def validateFirstName(name: String) = if (name.isEmpty) FirstNameEmpty.fail else name.success
def saveUser(ds: DataSource)(user: User): UserID = {
// blabla
}
abstract class UserValidationError
case object FirstNameEmpty extends UserValidationError
case object LastNameEmpty extends UserValidationError
def createUser(saveUser: User => UserID)(firstName: String, lastName: String): ValidationNel[UserValidationError, UserID] = {
def validateFirstName(name: String) = if (name.isEmpty) FirstNameEmpty.fail else name.success