Skip to content

Instantly share code, notes, and snippets.

View youroff's full-sized avatar

Ivan Yurov youroff

View GitHub Profile
---
title: Home
published: true
---
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>
@youroff
youroff / GenList.scala
Last active January 3, 2016 06:03
ScalaCheck custom list generator and sample property
package fpinscala.datastructures
import org.scalacheck.{Arbitrary, Gen}
object GenList {
import fpinscala.datastructures.{Cons, Nil, List}
def genList[A:Arbitrary]: Gen[List[A]] = for {
hd <- Arbitrary.arbitrary[A]
tl <- Gen.oneOf(nilGen, genList[A])
} yield Cons(hd, tl)
def cool_method
found = false
[1,2,3,4].each (item) ->
if item == 2
found = true
found
end
def transform(value, type = :unaltered)
case value
when Hash then value.deep_transform_keys! { |key| transform(key, type) }
when Symbol then transform(value.to_s, type).to_sym
when String
case type
when :dash then value.dasherize
when :camel then value.underscore.camelize
when :camel_lower then value.underscore.camelize(:lower)
when :underscore then value.underscore
require 'benchmark'
class Sqr
def initialize(xs)
@xs = xs
end
def run
puts "INLINE"
puts Benchmark.measure { @xs.map { |x| x * x } }