This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed abstract class Tree | |
case class Leaf(x: Int) extends Tree | |
case class Node(a: Tree, b: Tree) extends Tree | |
def sumTree(t: Tree): Int = { | |
def sumTreeHelper(trees: List[Tree], acc: Int): Int = trees match { | |
case Nil => acc | |
case Leaf(x) :: result => sumTreeHelper(result, x + acc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FILE "isSorted.scala" | |
def isSorted[A](as: Array[A], ordered: (A,A) => Boolean): Boolean = { | |
@annotation.tailrec | |
def go(n: Int): Boolean = | |
if (n >= as.length-1) true | |
else if (!ordered(as(n), as(n+1))) false | |
else go(n+1) | |
go(0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-----BEGIN PGP MESSAGE----- | |
Version: GnuPG v1 | |
owGtkltsTEEYx3dbWhUEaURKXSZSHtaaOdc5jTTBm3qouERTsWbmzNk9us5ZeymL | |
jQcRWkpdSmQbLSpuJaJEpGzckj40sZJKNYgXl4QqIiRFXM5pKqmEN/MyM9/8/t/3 | |
n2+mYWyuJ8ebrph+zwNWVHi7XlPPimcvBrYAautJULoFsLDJrbi7ssh6DkpBNU9S | |
EuN+055h2Tr3r4vNGGJ8oIZHY6ZtORT0Yz9SQMrn8q6ah3UeiweqTd09RRBRIqgU | |
MiIQAapElgxJgLpgaAbGnMuKjA2mYZkwBToTFjk2ZMxULHAIdapQBolT0DCtII9G | |
oqZrEUiciYQhJmoSM0QIuSxxpxLRqKrrmkCxpHLEKXSEITsW/+MyYNBpYNDeX/j/ | |
7DsxmI5SjAwo6bpqiIqmiFgVRMy4yLCsCwhpLhjj0aHGk3A1CZqW21MnWGMyPuxV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Licensed to the Apache Software Foundation (ASF) under one or more | |
* contributor license agreements. See the NOTICE file distributed with | |
* this work for additional information regarding copyright ownership. | |
* The ASF licenses this file to You under the Apache License, Version 2.0 | |
* (the "License"); you may not use this file except in compliance with | |
* the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.atomic.AtomicInteger | |
import cats._ | |
import cats.effect._ | |
import cats.effect.implicits._ | |
object foo extends IOApp { | |
import fs2._ | |
val ai = new AtomicInteger() | |
override def run(args: List[String]): IO[ExitCode] = |