Tag: Scala

Composite key handling, using @EmbeddedId annotation in scala

example simple : case class Group( id: Option[Id], category: Category, image: Option[FileResource] = None, updatedAt: LocalDateTime = NOW, createdAt: LocalDateTime = NOW ) extends EntityModel[Id] object Group { val Id = the[Identity[Id]] type Id = Long @@ GroupCommonIcon type WithNoId = Entity.WithNoId [Id, GroupCommonIcon] type EmbeddedId = Entity.EmbeddedId [Id, GroupCommonIcon] }

Advertisements

HeapSort in Scala – this is coding algorithm

import scala.collection.mutable.ArraySeq object HeapSort { def sort(vals: ArraySeq[Int]) { var heap = new MaxHeap heap.set(vals) for (i <- vals.length - 1 to 0 by -1) { vals(i) = heap.deleteMax } } } class MaxHeap { var _vals: ArraySeq[Int] = _ // First element is in 1, not 0. def set(vals: ArraySeq[Int]) { _vals = new … Continue reading HeapSort in Scala – this is coding algorithm

Selection Sort in Scala-This is coding algorithm

object Sort{ def selectionSort () : Unit = { var myArray = Array(4, 7, 8, 3, 1, 9, 2, 5, 0, 6) var buf:Int = 0; var min:Int = 0; for(i <- 0 to (myArray.length-1)) { min = i // j = i + 1; for (j <- (i+1) to (myArray.length)){ if ( myArray(min) > … Continue reading Selection Sort in Scala-This is coding algorithm

This is coding algorithm – Scala code bubble sort for loop

object Sort{ def bubbleSort () : Unit = { var myArray = Array(4, 7, 8, 3, 1, 9, 2, 5, 0, 6) var buf:Int = 0; for(i <- 0 to (myArray.length-1)) { for (j <- 1 to (myArray.length)){ if (myArray(j) < myArray(j-1)){ buf = myArray(j) myArray(j) = myArray(j-1) myArray(j-1) = buf } } } println("SORTED") … Continue reading This is coding algorithm – Scala code bubble sort for loop

install Scala version 2.12.4 news

The most popular way to get Scala is either using Scala through sbt, the Scala build tool, or to use Scala through an IDE. 1 First, make sure you have the Java 8 JDK installed. To check, open the terminal and type: java -version(Make sure you have version 1.8.) (If you don't have it installed, download … Continue reading install Scala version 2.12.4 news

Simple budget program in python

I've decided to start working on a budget application for the purposes of enhancing my Python skills. In its current form this program takes given expenses and income and tells the user whether they have a surplus, a deficit, or if they are breaking even. Example: import os import sys class Application(): def __init__(self): self.income … Continue reading Simple budget program in python

Asynchronous programming in Scala with Future

What is Future? A future object is an object whose value will be removed at some point in the future. This value is usually the result of a calculation process. This calculation returns the result value, we say that the Future object has completed that value, and vice versa. If an Exception is returned, the … Continue reading Asynchronous programming in Scala with Future

Array in scala enter form keyboard

This is function scala programer enter N element Interger form keyboard. Example: import scala.io._ object InputArray { def main(args: Array[String]): Unit = { println("Please enter n all element?") val n = StdIn.readInt() println("---------begin--------") val IntArr = Array.fill(n.toInt) { StdIn.readInt() } println("---------result--------") for (x <- IntArr) { println("x:" + x) } } } Reuslt:

Type Parameter is Scala

Class in Scala can receive a special parameter type, called Type Parameter. This type of parameter is not the same as normal variables as other parameters, but a parameter that specifies the type. That's why it's called Type Parameter. While Class is defined, it is entirely possible to manipulate an unknown type (specified when calling … Continue reading Type Parameter is Scala