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
package main | |
import ( | |
"fmt" | |
) | |
type Named struct { | |
name string | |
} |
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
// Runtime polymorphism | |
trait Closeable { | |
def name: String | |
def close: String | |
} | |
case class Connection(override val name: String, database: String) extends Closeable { | |
override def close: String = s"Closing connection $name" |
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
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"net/http" | |
"strings" | |
) | |
type Result struct { |
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 akka.actor.ActorSystem | |
import akka.stream.ActorMaterializer | |
import play.api.libs.ws._ | |
import play.api.libs.ws.ahc._ | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits._ | |
import play.api.libs.json._ | |
implicit val system = ActorSystem() |
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
package main | |
import "fmt" | |
import "strings" | |
func main() { | |
dictionary := make(map[string]int) | |
words := []string{"Fear", "of", "a", "name", "only", "increases", "fear", "of", "the", "thing", "itself"} | |
for _, word := range words { | |
word = strings.ToLower(word) |
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
val words = List("Fear", "of", "a", "name", "only", "increases", "fear", "of", "the", "thing", "itself") | |
words | |
.groupBy(_.toLowerCase) | |
.mapValues(_.size) |
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
package main | |
import "fmt" | |
import "math" | |
func squareRoot(value int) (float64, error) { | |
if value >= 0 { | |
return math.Sqrt(float64(value)), nil | |
} else { | |
return 0, fmt.Errorf("invalid input: %v", value) |
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 scala.util.{Failure, Success, Try} | |
def squareRoot(value: Int): Try[Double] = { | |
if (value >= 0) { | |
Success(Math.sqrt(value)) | |
} else { | |
Failure(new IllegalArgumentException("Value cannot be negative")) | |
} | |
} | |
val sum = for { |
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
case class Student(name: String, house: String) | |
def findStudent(key: Int): Option[Student] = { | |
val students = Map( | |
1 -> Student("Harry Potter", "Hogwarts"), | |
3 -> Student("Draco Malfoy", "Slytherin") | |
) | |
students.get(key) | |
} |
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
package main | |
import "fmt" | |
type Student struct { | |
name string | |
house string | |
} | |
func findStudent(key int) (Student, bool) { |
NewerOlder