Skip to content

Instantly share code, notes, and snippets.

@YuvalItzchakov
YuvalItzchakov / gist:c24c51747226e9a64f6a
Created November 12, 2014 15:09
generic vs non-generic state machine
C# code:
IEnumerable NonGenericEmptyEnumerable()
{
yield break;
}
IEnumerable<T> GenericEmptyEnumerable<T>()
{
yield break;
public static void Main(string[] args)
{
var sInstance = new Structure(25);
sInstance.Change(35);
await sInstance.ChangeAsync(45);
}
public struct Structure
{
private int value;
public class Program
{
public static void Main(string[] args)
{
new BenchmarkRunner().RunCompetition(new IL_Loops());
}
}
public class IL_Loops
{
List<int> collection = GetCollection();
if ((collection?.Any(x => x > 5))
{
// Is the collection null, or isn't there any element?
}
else
{
// I want to access the list here, need to add a null check:
if (collection != null)
...
static void GetSize(string msg)
{
byte[] data = Encoding.ASCII.GetBytes(msg);
byte[] sizeinfo = new byte[4];
sizeinfo[0] = (byte)data.Length;
sizeinfo[1] = (byte)(data.Length >> 8);
sizeinfo[2] = (byte)(data.Length >> 16);
sizeinfo[3] = (byte)(data.Length >> 24);
}
[info] +-io.argonaut:argonaut_2.10:6.1
[info] | +-com.github.julien-truffaut:monocle-core_2.10:1.1.0 [S]
[info] | | +-org.scalaz:scalaz-core_2.10:7.1.1 [S] (evicted by: 7.2.0)
[info] | | +-org.scalaz:scalaz-core_2.10:7.2.0 [S]
[info] | |
[info] | +-com.github.julien-truffaut:monocle-macro_2.10:1.1.0 [S]
[info] | | +-com.github.julien-truffaut:monocle-core_2.10:1.1.0 [S]
[info] | | | +-org.scalaz:scalaz-core_2.10:7.1.1 [S] (evicted by: 7.2.0)
[info] | | | +-org.scalaz:scalaz-core_2.10:7.2.0 [S]
[info] | | |
object Yuval extends App {
class Animal {
this: Reflect =>
}
implicit def reflectOrdering: Ordering[Animal with Reflect] = Ordering.by(e => e.canReflect)
object Animal {
def isGreaterAnimal(first: Animal with Reflect, second: Animal with Reflect)(implicit ev: Ordering[Animal with Reflect]) = ev.gt(first, second)
}
scala> Array(1,2,3,4).sliding(2).forall {
| case Array(x, y) => x < y
| case _ => true
| }
res4: Boolean = true
@YuvalItzchakov
YuvalItzchakov / HolyShitThisWorks.scala
Created April 15, 2017 16:12
Lazy dropWhile with Cats
package tests
import cats._
import cats.implicits._
import scala.collection.immutable.Stream
/**
* Created by Yuval.Itzchakov on 3/8/2017.
*/
object Test {

Keybase proof

I hereby claim:

  • I am yuvalitzchakov on github.
  • I am yuvalitzchakov (https://keybase.io/yuvalitzchakov) on keybase.
  • I have a public key ASCNpDl4BcEt30uHFcNQkS_p_aZKQ7q_1blOJq34f0XoSgo

To claim this, I am signing this object: