Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Delucchi ryanonsrc

  • nary.io
  • San Jose, CA
View GitHub Profile
View tmux.conf
# 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 %
View keybase.md

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:

View Advanced-FP-with-Scala.md

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
View Fold-That-Shit-2
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
}
View Fold-That-Shit
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
}
View gist:e3a07fe146d58501283b
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
@ryanonsrc
ryanonsrc / automata.scala
Last active Jun 7, 2019
Scala implementation of a Non-deterministic Finite Automata (Finite State Machine), supporting ε-Transitions.
View automata.scala
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;