Skip to content

Instantly share code, notes, and snippets.

View anthonyshull's full-sized avatar

Anthony Shull anthonyshull

  • Austin, TX
View GitHub Profile
@anthonyshull
anthonyshull / transmit.fs
Last active February 2, 2018 16:05
Electricity Transmission
type Transmit = Station -> Station -> Supply option -> Station * Station
let transmit (fStation: Station) (tStation: Station) (supply: Supply option) =
match fStation, tStation, supply with
| PowerStation fStation, TransmissionSubstation tStation, Some (Supply supply) ->
match fStation.Supply, tStation.Supply with
| Some (Supply fStationSupply), Some (Supply tStationSupply) ->
if fStationSupply > supply then
PowerStation { fStation with Supply = Supply (fStationSupply - supply) },
TransmissionSubstation { tStation with Supply = Supply (tStationSupply + supply) }
@anthonyshull
anthonyshull / electricity.fs
Last active February 2, 2018 16:04
Domain Modeling with F#
open Microsoft.FSharp.Data.UnitSystems.SI.UnitNames
type Supply = Supply of float<watt>
let Supply (electricity: float<watt>) =
if electricity > 0.0<watt> then
Some (Supply electricity)
else
None