Skip to content

Commit

Permalink
Extend the use of the KoanAttribute to work on classes and provide a …
Browse files Browse the repository at this point in the history
…facility to specify the sort order.
  • Loading branch information
panesofglass committed Jun 8, 2012
1 parent 6f809e9 commit bb5dff3
Show file tree
Hide file tree
Showing 22 changed files with 29 additions and 2 deletions.
6 changes: 5 additions & 1 deletion FSharpKoans.Core/KoanAttribute.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

open System

[<AttributeUsage(AttributeTargets.Method, AllowMultiple = false)>]
[<AttributeUsage(AttributeTargets.Class ||| AttributeTargets.Method, AllowMultiple = false)>]
type KoanAttribute () =
inherit Attribute()
let mutable sortOrder = 0
member x.Sort
with get() = sortOrder
and set(v) = sortOrder <- v
5 changes: 4 additions & 1 deletion FSharpKoans.Core/KoanRunner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ type KoanRunner(containers) =
new () =
let containers =
Assembly.GetCallingAssembly().GetTypes()
|> Array.filter (not << Seq.isEmpty << KoanContainer.findKoanMethods)
|> Array.map (fun t -> t, t.GetCustomAttributes(typeof<KoanAttribute>, true))
|> Array.filter (not << Seq.isEmpty << snd)
|> Array.sortBy (fun (t, attrs) -> (attrs.[0] :?> KoanAttribute).Sort)
|> Array.map fst
KoanRunner(containers)

member this.ExecuteKoans() =
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutArrays.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open System.Collections.Generic
//
// Like lists, arrays are another basic container type in F#.
//---------------------------------------------------------------
[<Koan(Sort = 11)>]
module ``about arrays`` =
[<Koan>]
let CreatingArrays() =
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutAsserts.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace FSharpKoans
open FSharpKoans.Core

[<Koan(Sort = 1)>]
module ``about asserts`` =

// We shall contemplate truth by testing reality, via asserts.
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutBranching.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open FSharpKoans.Core
// Branching is used to tell a program to conditionally perform
// an operation. It's another fundamental part of F#.
//---------------------------------------------------------------
[<Koan(Sort = 8)>]
module ``about branching`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutClasses.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Person2(name:string) =
member this.Speak() =
"Hi my name is " + this.Name

[<Koan(Sort = 20)>]
module ``about classes`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutDiscriminatedUnions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Favorite =
// of them like a much more powerful version of enums in other
// languages.
//---------------------------------------------------------------
[<Koan(Sort = 18)>]
module ``about discriminated unions`` =
[<Koan>]
let DiscriminatedUnionsCaptureASetOfOptions() =
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutDotNetCollections.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open System.Collections.Generic
// languages, you can use all of the basic .NET collections types
// you're already familiar with if you're a C# or VB programmer.
//---------------------------------------------------------------
[<Koan(Sort = 12)>]
module ``about dot net collections`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open FSharpKoans.Core
// Now that you've seen how to bind a name to a value with let,
// you'll learn to use the let keyword to create functions.
//---------------------------------------------------------------
[<Koan(Sort = 3)>]
module ``about functions`` =

(* By default, F# is whitespace sensitive.
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutLet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open FSharpKoans.Core
// You'll use it in almost every line of F# code you write, so
// let's get to know it well! (no pun intended)
//---------------------------------------------------------------
[<Koan(Sort = 2)>]
module ``about let`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutLists.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ open System.Collections.Generic
// list and perform operations across each value in the
// list.
//---------------------------------------------------------------
[<Koan(Sort = 9)>]
module ``about lists`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutLooping.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open FSharpKoans.Core
// back on traditional imperative looping techniques that you may
// be more familiar with.
//---------------------------------------------------------------
[<Koan(Sort = 13)>]
module ``about looping`` =
[<Koan>]
let LoopingOverAList() =
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutModules.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module MushroomKingdom =
// They're similar to .NET namespaces, but they have slightly
// different semantics as you'll see below.
//---------------------------------------------------------------
[<Koan(Sort = 19)>]
module ``about modules`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutOptionTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Game = {
// in other languages. However, using option types instead of nulls
// has subtle but far reaching benefits.
//---------------------------------------------------------------
[<Koan(Sort = 17)>]
module ``about option types`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutPipelining.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open FSharpKoans.Core
// symbols in F# programming. You can use it combine operations
// on lists and other data structures in a readable way.
//---------------------------------------------------------------
[<Koan(Sort = 10)>]
module ``about pipelining`` =

let square x =
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutRecordTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Character = {
// You can use them to group data in a more structured way than
// tuples.
//---------------------------------------------------------------
[<Koan(Sort = 16)>]
module ``about record types`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutStrings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open FSharpKoans.Core
// Most languages have a set of utilities for manipulating
// strings. F# is no different.
//---------------------------------------------------------------
[<Koan(Sort = 7)>]
module ``about strings`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutTheOrderOfEvaluation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open FSharpKoans.Core
// functions are evaluated. F# offers a couple mechanisms for
// doing this.
//---------------------------------------------------------------
[<Koan(Sort = 4)>]
module ``about the order of evaluation`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutTheStockExample.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ open FSharpKoans.Core
// let splitCommas (x:string) =
// x.Split([|','|])
//---------------------------------------------------------------
[<Koan(Sort = 15)>]
module ``about the stock example`` =

let stockData =
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutTuples.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open FSharpKoans.Core
// Tuples are used to easily group together values in F#. They're
// another fundamental construct of the language.
//---------------------------------------------------------------
[<Koan(Sort = 6)>]
module ``about tuples`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/AboutUnit.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ open Microsoft.FSharp.Reflection
// a value. It's similar to void in other languages, but unit
// is actually considered to be a type in F#.
//---------------------------------------------------------------
[<Koan(Sort = 5)>]
module ``about unit`` =

[<Koan>]
Expand Down
1 change: 1 addition & 0 deletions FSharpKoans/MoreAboutFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open FSharpKoans.Core
// since F# is a functional language, there are more tricks
// to learn!
//---------------------------------------------------------------
[<Koan(Sort = 14)>]
module ``more about functions`` =

[<Koan>]
Expand Down

0 comments on commit bb5dff3

Please sign in to comment.