Skip to content

Instantly share code, notes, and snippets.

View ryanonsrc's full-sized avatar

Ryan Delucchi ryanonsrc

  • nary.io
  • San Jose, CA
View GitHub Profile
@ryanonsrc
ryanonsrc / automata.scala
Last active June 7, 2019 13:17
Scala implementation of a Non-deterministic Finite Automata (Finite State Machine), supporting ε-Transitions.
package io.nary.automata
// Models a transition, tied to a specific StateMachine sub-type. The guard condition is not required.
class Transition[S, M <: StateMachine[S, M]](start: S, end :S, guard: Option[M => Boolean]) {
val startState = start
val endState = end
// Given a state machine and whether a guard is expected, should we follow this transition?
def willFollow(stateMachine: M, withGuard : Boolean) =
if (!withGuard && guard == None) true;
trait QId; trait QSection; trait QProjectType; trait QName
trait QFriendlyName; trait QDescription; trait QCode; trait QAnswers
case class Answer(text: String)
object QuestionTypes {
type FormQuestionId = Long @@ QId
type Section = String @@ QSection
type ProjectType = String @@ QProjectType
type Name = String @@ QName
object BinaryAddition {
def binaryAddition(a: Array[Int], b: Array[Int]): Array[Int] =
((Array.empty[Int] -> 0) /: (a zip b)) { case ((c, carry), (ai, bi)) =>
(((ai + bi + carry) % 2) +: c) -> (ai + bi + carry) / 2
}._1
}
object BinaryAddition {
def binaryAddition(a: Array[Int], b: Array[Int]): Array[Int] =
((Array.empty[Int] -> 0) /: (a zip b)) { case ((c, carry), (ai, bi)) =>
((sum:Int) => ((sum % 2) +: c) -> (sum / 2))(ai + bi + carry)
}._1
}

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x

Keybase proof

I hereby claim:

  • I am ryanonsrc on github.
  • I am ryanonsrc (https://keybase.io/ryanonsrc) on keybase.
  • I have a public key ASAYeEaRPEU5C4vcQcy1_89hCr2ZUSJXdKSjnEYu-B0jzgo

To claim this, I am signing this object:

# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# split panes using | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %