Skip to content

Instantly share code, notes, and snippets.

@non
non / Extended.scala
Last active August 29, 2015 14:22
Generic implementation of affinely extended real number system in Scala using Spire. https://en.wikipedia.org/wiki/Extended_real_number_line
package spire.math
import scala.{specialized => sp}
import spire.algebra._
import spire.math._
import spire.syntax.all._
/**
* Implementation of extended real numbers.
@non
non / cats-testing-challenge.md
Last active August 29, 2015 14:22
Help improve the Cats project's test coverage, get a hand-drawn cat sent to you!

🐈 Cats Test Coverage Challenge 🐈

Recently the Cats project has started using codecov.io to track test coverage of our project. As of writing our tests cover about 48% of the core subproject.

One of the benefits that we get from pure functional programming is that there are fewer ways to make mistakes. Nonetheless, we value having a robust test suite which exercises and verifies the properties of our code.

Writing tests is a great way to get involved with the Cats project! The project currently marks test-related issues with a testing label, and we use an in-progress label to signal that someone is working on the issue.

The Challenge

@non
non / ContT.scala
Created June 15, 2015 14:08
Basic port of Control.Monad.ContT
package cats
package data
import cats.syntax.all._
trait ContT[R, M[_], A] {
def run(f: A => M[R]): M[R]
def mapResult(f: M[R] => M[R]): ContT[R, M, A] =
ContT(c => f(run(c)))
@non
non / syntax2.md
Created June 26, 2015 07:03
Start of some documentation around Cats syntax. Work-in-progress.

Cats Syntax Guide

This project introduces some new syntax and constructions which might not be familiar to the reader. This document is an overview of certain patterns you might see in Cats, what they mean, and how they are used.

Introduction to Kinds

Many of the type classes in Cats are paraterized on a type with the shape F[_], i.e. a type constructor that takes a type argument, and

package cats
import cats.implicits._
// this is translation of the work at:
//
// https://ku-fpg.github.io/files/Sculthorpe-13-ConstrainedMonad.pdf
//
// into Scala using the Cats library
public <A extends java/lang/Object> java.lang.String withImplicitly(scala.math.Ordering<A>);
Code:
0: getstatic #16 // Field scala/Predef$.MODULE$:Lscala/Predef$;
3: aload_1
4: invokevirtual #20 // Method scala/Predef$.implicitly:(Ljava/lang/Object;)Ljava/lang/Object;
7: invokevirtual #24 // Method java/lang/Object.getClass:()Ljava/lang/Class;
10: invokevirtual #30 // Method java/lang/Class.getName:()Ljava/lang/String;
13: areturn
public <A extends java/lang/Object> java.lang.String withExplicitParam(scala.math.Ordering<A>);
@non
non / ueq.md
Last active August 29, 2015 14:25

test.scala

package test

case class UByte(val byte: Byte) extends AnyVal {
  def ==(rhs: UByte): Boolean = byte == rhs.byte
}

class Test {
@non
non / updater.py
Created July 28, 2015 22:57
Script to use with [awesome-scala](https://github.com/lauris/awesome-scala) to format README.md and add useful metadata.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# by Erik Osheim
#
# Reads README.md, and writes a README.md.new. If the format of
# README.md changes, this script may need modifications.
#
# Currently it rewrites each section, doing the following:
# 1. alphabetizing

These are some errors I got while running test in non/algebra. It seems like maybe scala.js's Int emulation is not perfect.

[info] - [Int].order.antisymmetry *** FAILED ***
[info]   GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation.
[info]    (algebra-laws-test-fastopt.js:25526)
[info]     Falsified after 22 successful property evaluations.
[info]     Location: (algebra-laws-test-fastopt.js:25526)
[info]     Occurred when passed generated values (
[info]       arg0 = -2147483648,
@non
non / AdHocTest.scala
Created July 29, 2015 15:02
Test demonstrating possible scala.js/algebra bug.
package algebra
package laws
import org.scalatest.FunSuite
class AdHocTest extends FunSuite {
test("literal ops") {
val x0 = -2147483648
val y0 = 2147483647