-
-
Save wk-j/93c8b335ea1336ac5f420b32a9f1fa75 to your computer and use it in GitHub Desktop.
Helpful functions for working with pairs in F#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Tuple2 | |
let replicate x = x, x | |
let curry f x y = f (x, y) | |
let uncurry f (x, y) = f x y | |
let swap (x, y) = (y, x) | |
let mapFst f (x, y) = f x, y | |
let mapSnd f (x, y) = x, f y | |
let extendFst f (x,y) = f (x,y), y | |
let extendSnd f (x,y) = x, f(x,y) | |
let optionOfFst f (x, y) = | |
match f x with | |
| Some x' -> Some (x', y) | |
| None -> None | |
let optionOfSnd f (x, y) = | |
match f y with | |
| Some y' -> Some (x, y') | |
| None -> None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment