1 people like it.

Coord

Playing with coordinates and moves See https://github.com/giuliohome/AdventOfCode2019/blob/master/Day15-Part1-QueueVersion.fs#L54-L66

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
type Position = {X:int;Y:int}
let back = function
    | 1L -> 2L
    | 2L -> 1L
    | 3L -> 4L
    | 4L -> 3L
    | _ -> failwith "wrong direction"
let moveTo = function
    | 1L -> fun position -> {position with Y = position.Y + 1}
    | 2L -> fun position -> {position with Y = position.Y - 1}
    | 3L -> fun position -> {position with X = position.X - 1}
    | 4L -> fun position -> {position with X = position.X + 1}
    | _ -> failwith "wrong direction" 
Position.X: int
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
Position.Y: int
val back : _arg1:int64 -> int64

Full name: Script.back
val failwith : message:string -> 'T

Full name: Microsoft.FSharp.Core.Operators.failwith
val moveTo : _arg1:int64 -> (Position -> Position)

Full name: Script.moveTo
val position : Position
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/7Xr
Posted:4 years ago
Author:giuliohome
Tags: function , function composition , list , pattern matching