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
let isEven num = num % 2 = 0 | |
let square num = num * num | |
let printResults = List.iter <| printfn "%d" | |
// Filter then map | |
[1..5] | |
|> List.filter isEven | |
|> List.map square | |
|> printResults |
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
let rec fold f state list = | |
match list with | |
| [] -> state | |
| head::rest -> fold f (f state head) rest | |
let reduce f list = | |
match list with | |
| [] -> invalidArg "list" "Cannot pass an empty list" | |
| head::rest -> fold f head rest |
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
import java.util.function.BiFunction; | |
import java.util.List; | |
import java.util.Arrays; | |
public class FunctionsExample { | |
public static void main(String[] args) { | |
String[] strs = {"Example", "Strings", "To", "Join"}; | |
List<String> strsList = Arrays.asList(strs); | |
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
type Peano = | |
| Zero | |
| Succ of Peano | |
// Comapre | |
let rec cmp x y = | |
match x, y with | |
| Zero, Zero -> 0 | |
| Zero, Succ _ -> -1 | |
| Succ _, Zero -> 1 |
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
namespace ConsList | |
module List = | |
type 'a List = | |
| Nil | |
| Cons of ('a * 'a List) | |
let private asCons v = Cons (v, Nil) |
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
type 'a Node = Group of 'a Node list | Leaf of 'a | |
let tree = Group [ Group [Leaf 1; Leaf 2; Leaf 3]; Group [Leaf 6]; Leaf 9; Leaf 10 ] | |
let isEven n = n % 2 = 0 | |
let flip f a b = f b a | |
let (>>=) = flip List.collect | |
let rec collectLeavesBy predicate = function | |
| Group xs -> xs >>= (collectLeavesBy predicate) |
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
open System | |
open System.Net | |
open System.Threading | |
[<EntryPoint>] | |
let main _ = | |
let url = "http://www.google.com" | |
let (>>=) (asyncBlock: Async<'a>) (f: 'a -> Async<'b>) = | |
async { |
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
type 'a Node = | |
| Leaf of 'a | |
| Group of ('a Node * 'a Node) | |
let findTreeHeight tree = | |
let rec aux tree counter = | |
match tree with | |
| Leaf _ -> counter | |
| Group (left, right) -> | |
let leftTreeHeight = aux left (counter + 1) |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace OptionExample | |
{ | |
public interface IOption<T> | |
{ | |
bool IsSome { get; } | |
bool IsSomeOf(T value); |
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 AoCDay8Part1 where | |
data Node = Node [Node] [Int] | |
solve :: [Int] -> ([Int], Node) | |
solve (nChild:nEntries:rest) = | |
(remainingToBeParsed, Node children entries) | |
where | |
remainingToBeParsed = drop nEntries restChildren | |
entries = take nEntries restChildren |
OlderNewer