You are forced to do checks for None
and Some
and methods like map
or flatMap
make your code uglier.
Replace the optional value with null:
val customer: Option[Customer] = getCustomer(customerId)
val plan = customer.map(_.plan)
static class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var list = new List<int> {4, 5, 4, 7, 9, 1, 6, 1, 0, -99, 10000, 3, 2}; | |
var sorted = list.QuickSort(); | |
Console.WriteLine(String.Join(", ", sorted)); | |
// output: -99, 0, 1, 1, 2, 3, 4, 4, 5, 6, 7, 9, 10000 |
public static class CondictionalsExtensions | |
{ | |
public static Tuple<bool, T> If<T>(this T src, Predicate<T> p) | |
{ | |
return p(src) | |
? Tuple.Create(true, src) | |
: Tuple.Create(false, src); | |
} | |
public static Tuple<bool, T, R> Then<T, R>(this Tuple<bool, T> src, Func<T, R> f) |
module Git = | |
open System | |
open System.Diagnostics | |
let private runCommand cmd args = | |
let startInfo = new ProcessStartInfo() | |
startInfo.FileName <- cmd | |
startInfo.Arguments <- args | |
startInfo.UseShellExecute <- false | |
startInfo.RedirectStandardOutput <- true |
public class EditedPair<T> | |
{ | |
public EditedPair(T old, T @new) | |
{ | |
Old = old; | |
New = @new; | |
} | |
public T Old { get; private set; } | |
public T New { get; private set; } |
package futureeitherapplicativestack | |
import cats._ | |
import cats.data._ | |
import cats.implicits._ | |
import scala.concurrent.{Await, Future} | |
import scala.concurrent.duration.Duration | |
import scala.concurrent.ExecutionContext.Implicits.global |
#load @"paket-files/fsprojects/Chessie/src/Chessie/ErrorHandling.fs" | |
open System | |
open Chessie.ErrorHandling | |
type Person = { FirstName: string; LastName: string } | |
let id1 = Guid.NewGuid() | |
let id2 = Guid.NewGuid() |
[<AutoOpen>] | |
module IO = | |
type IO<'a> = | |
private | |
| Return of (unit -> 'a) | |
| Suspend of (unit -> IO<'a>) | |
let rec run x = | |
match x with | |
| Return v -> v() |
#load @"paket-files/fsprojects/Chessie/src/Chessie/ErrorHandling.fs" | |
type Continuation<'output, 'next> = 'output -> 'next | |
module TerminalDsl = | |
open Chessie.ErrorHandling | |
type Terminal<'next> = | |
| WriteLine of string * Continuation<unit, 'next> | |
| ReadLine of unit * Continuation<string, 'next> |