-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement
map
, iter
and length
- Loading branch information
1 parent
1e92f99
commit a673d90
Showing
5 changed files
with
34 additions
and
86 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module FSharp.Control.Observable | ||
|
||
open R3 | ||
open System.Threading | ||
open System.Threading.Tasks | ||
|
||
let asyncMap (f : 't -> Async<'r>) source = | ||
let selector x ct = ValueTask<'r> (Async.StartImmediateAsTask (f x, ct)) | ||
ObservableExtensions.SelectAwait (source, selector) | ||
|
||
let mapAsync (f : CancellationToken -> 't -> Task<'r>) source = | ||
let selector x ct = ValueTask<'r> (f ct x) | ||
ObservableExtensions.SelectAwait (source, selector) | ||
|
||
let inline map (f : 't -> 'r) source = ObservableExtensions.Select (source, f) | ||
|
||
let length source = async { | ||
let! ct = Async.CancellationToken | ||
return! | ||
ObservableExtensions.CountAsync (source, ct) | ||
|> Async.AwaitTask | ||
} | ||
|
||
let inline iter (action : 't -> unit) source = ObservableExtensions.ForEachAsync (source, action) | ||
|
||
let asyncIter (action : 't -> Async<unit>) source = source |> asyncMap action |> length |> Async.Ignore | ||
|
||
let iterAsync (action : CancellationToken -> 't -> Task<unit>) source = source |> mapAsync action |> length |> Async.Ignore |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,9 @@ | ||
namespace FSharp.Control.R3.Tests | ||
|
||
open System | ||
open FSharp.Control.R3 | ||
open FSharp.Control.R3.Say | ||
open FSharp.Control | ||
open Microsoft.VisualStudio.TestTools.UnitTesting | ||
open Swensen.Unquote | ||
|
||
[<TestClass>] | ||
type SayTests () = | ||
|
||
member _.``Add two integers`` () = | ||
let subject = Say.add 1 2 | ||
test <@ subject = 3 @> | ||
//Assert.AreEqual (subject, 3, message = "Addition works") | ||
|
||
member _.``Say nothing`` () = | ||
let subject = Say.nothing () | ||
Assert.AreEqual (subject, (), "Not an absolute unit") | ||
|
||
member _.``Say hello all`` () = | ||
let person = { | ||
Name = "Jean-Luc Picard" | ||
FavoriteNumber = 4 | ||
FavoriteColor = Red | ||
DateOfBirth = DateTimeOffset.Parse ("July 13, 2305") | ||
} | ||
|
||
let subject = Say.helloPerson person | ||
|
||
test <@ subject = "Hello Jean-Luc Picard. You were born on 2305/07/13 and your favorite number is 4. You like Red." @> | ||
|
||
//Assert.AreEqual<String> ( | ||
// subject, | ||
// "Hello Jean-Luc Picard. You were born on 2305/07/13 and your favorite number is 4. You like Red.", | ||
// message = "You didn't say hello" | ||
//) | ||
type SayTests () = class end |