diff --git a/.paket/Paket.Restore.targets b/.paket/Paket.Restore.targets
index a86be3a1..e7c1bc0c 100644
--- a/.paket/Paket.Restore.targets
+++ b/.paket/Paket.Restore.targets
@@ -23,6 +23,9 @@
<_PaketExeExtension>$([System.IO.Path]::GetExtension("$(PaketExePath)"))
dotnet "$(PaketExePath)"
+
+ "$(PaketExePath)"
+
$(PaketRootPath)paket.bootstrapper.exe
$(PaketToolsPath)paket.bootstrapper.exe
"$(PaketBootStrapperExePath)"
@@ -50,10 +53,10 @@
-
+
-
+
@@ -145,9 +148,10 @@
+
diff --git a/.paket/paket.exe b/.paket/paket.exe
index e441f7c2..b98e000b 100644
Binary files a/.paket/paket.exe and b/.paket/paket.exe differ
diff --git a/src/Disco/Disco/Client/ApiClient.fs b/src/Disco/Disco/Client/ApiClient.fs
index c622132a..8452f21c 100644
--- a/src/Disco/Disco/Client/ApiClient.fs
+++ b/src/Disco/Disco/Client/ApiClient.fs
@@ -189,7 +189,7 @@ module ApiClient =
let private handleServerRequest (state: ClientState) (req: Request) (agent: ApiAgent) =
match req.Body |> Binary.decode with
- | Right (ApiRequest.Snapshot snapshot) ->
+ | Ok (ApiRequest.Snapshot snapshot) ->
state.Socket.Status
|> String.format "received snapshot (status: {0})"
|> Logger.info (tag "handleServerResponse")
@@ -197,12 +197,12 @@ module ApiClient =
|> Msg.SetState
|> agent.Post
- | Right (ApiRequest.Update sm) ->
+ | Ok (ApiRequest.Update sm) ->
sm
|> Msg.Update
|> agent.Post
- | Right other ->
+ | Ok other ->
string other
|> ApiError.UnknownCommand
|> ApiResponse.NOK
@@ -210,7 +210,7 @@ module ApiClient =
|> Response.fromRequest req
|> state.Socket.Respond
- | Left error ->
+ | Error error ->
error
|> string
|> ApiError.MalformedRequest
@@ -230,7 +230,7 @@ module ApiClient =
// | _ < __/ (_| | \__ \ || __/ | | __/ (_| |
// |_| \_\___|\__, |_|___/\__\___|_| \___|\__,_|
// |___/
- | Right ApiResponse.Registered ->
+ | Ok ApiResponse.Registered ->
Logger.info (tag "handleClientResponse") "registration successful"
ClientEvent.Registered |> Msg.Notify |> agent.Post
@@ -240,7 +240,7 @@ module ApiClient =
// | |_| | | | | _ < __/ (_| | \__ \ || __/ | | __/ (_| |
// \___/|_| |_|_| \_\___|\__, |_|___/\__\___|_| \___|\__,_|
// |___/
- | Right ApiResponse.Unregistered ->
+ | Ok ApiResponse.Unregistered ->
Logger.info (tag "handleClientResponse") "un-registration successful"
ClientEvent.UnRegistered |> Msg.Notify |> agent.Post
agent.Post Msg.Dispose
@@ -250,14 +250,14 @@ module ApiClient =
// | \| | | | | ' /
// | |\ | |_| | . \
// |_| \_|\___/|_|\_\
- | Right (ApiResponse.NOK error) -> error |> string |> Logger.err (tag "handleClientResponse")
+ | Ok (ApiResponse.NOK error) -> error |> string |> Logger.err (tag "handleClientResponse")
// ____ _ _____
// | _ \ ___ ___ ___ __| | ___ | ____|_ __ _ __ ___ _ __
// | | | |/ _ \/ __/ _ \ / _` |/ _ \ | _| | '__| '__/ _ \| '__|
// | |_| | __/ (_| (_) | (_| | __/ | |___| | | | | (_) | |
// |____/ \___|\___\___/ \__,_|\___| |_____|_| |_| \___/|_|
- | Left error -> error |> string |> Logger.err (tag "handleClientResponse")
+ | Error error -> error |> string |> Logger.err (tag "handleClientResponse")
state
// ** handleSocketEvent
@@ -376,7 +376,7 @@ module ApiClient =
// **** Start
member self.Start () =
- either {
+ result {
server.Port
|> sprintf "Connecting to server on %O:%O" server.IpAddress
|> Logger.info (tag "start")
@@ -387,7 +387,7 @@ module ApiClient =
// **** Restart
member self.Restart(server: DiscoServer) =
- server |> Msg.Restart |> agent.Post |> Either.succeed
+ server |> Msg.Restart |> agent.Post |> Result.succeed
// **** State
diff --git a/src/Disco/Disco/Client/ApiRequest.fs b/src/Disco/Disco/Client/ApiRequest.fs
index abbac646..589725df 100644
--- a/src/Disco/Disco/Client/ApiRequest.fs
+++ b/src/Disco/Disco/Client/ApiRequest.fs
@@ -56,17 +56,17 @@ type ApiError =
match fb.Type with
| ApiErrorTypeFB.InternalFB ->
Internal fb.Data
- |> Either.succeed
+ |> Result.succeed
| ApiErrorTypeFB.UnknownCommandFB ->
UnknownCommand fb.Data
- |> Either.succeed
+ |> Result.succeed
| ApiErrorTypeFB.MalformedRequestFB ->
MalformedRequest fb.Data
- |> Either.succeed
+ |> Result.succeed
| x ->
sprintf "Unknown ApiErrorFB: %A" x
|> Error.asClientError "ApiErrorFB.FromFB"
- |> Either.fail
+ |> Result.fail
// * ApiRequest
@@ -157,6 +157,13 @@ type ApiRequest =
| Update (AddMember mem as cmd)
| Update (UpdateMember mem as cmd)
| Update (RemoveMember mem as cmd) ->
+ mem
+ |> Binary.toOffset builder
+ |> withPayload ParameterFB.ClusterMemberFB cmd.ApiCommand
+
+ | Update (AddMachine mem as cmd)
+ | Update (UpdateMachine mem as cmd)
+ | Update (RemoveMachine mem as cmd) ->
mem
|> Binary.toOffset builder
|> withPayload ParameterFB.RaftMemberFB cmd.ApiCommand
@@ -308,7 +315,7 @@ type ApiRequest =
// |____/|_| |_|\__,_| .__/|___/_| |_|\___/ \__|
// |_|
| ApiCommandFB.SnapshotFB, ParameterFB.StateFB ->
- either {
+ result {
let! state =
let statish = fb.Parameter()
if statish.HasValue then
@@ -317,12 +324,12 @@ type ApiRequest =
else
"Empty StateFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return Snapshot state
}
| ApiCommandFB.DataSnapshotFB, ParameterFB.StateFB ->
- either {
+ result {
let! state =
let statish = fb.Parameter()
if statish.HasValue then
@@ -331,7 +338,7 @@ type ApiRequest =
else
"Empty StateFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update(DataSnapshot state)
}
@@ -343,7 +350,7 @@ type ApiRequest =
| ApiCommandFB.RegisterFB, ParameterFB.DiscoClientFB ->
let clientish = fb.Parameter()
if clientish.HasValue then
- either {
+ result {
let value = clientish.Value
let! client = DiscoClient.FromFB(value)
return Register client
@@ -351,12 +358,12 @@ type ApiRequest =
else
"Empty DiscoClientFB Parameter in ApiRequest"
|> Error.asClientError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
| ApiCommandFB.UnRegisterFB, ParameterFB.DiscoClientFB ->
let clientish = fb.Parameter()
if clientish.HasValue then
- either {
+ result {
let value = clientish.Value
let! client = DiscoClient.FromFB(value)
return UnRegister client
@@ -364,7 +371,7 @@ type ApiRequest =
else
"Empty DiscoClientFB Parameter in ApiRequest"
|> Error.asClientError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
// ____ _ _
// | _ \ _ __ ___ (_) ___ ___| |_
@@ -375,9 +382,9 @@ type ApiRequest =
| ApiCommandFB.UnloadFB, _ ->
UnloadProject
|> ApiRequest.Update
- |> Either.succeed
+ |> Result.succeed
| ApiCommandFB.UpdateFB, ParameterFB.ProjectFB ->
- either {
+ result {
let! project =
let projectish = fb.Parameter()
if projectish.HasValue then
@@ -386,7 +393,7 @@ type ApiRequest =
else
"Empty DiscoProjectFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateProject project)
}
@@ -396,7 +403,7 @@ type ApiRequest =
// | |__| (_) | | | | | | | | | | | (_| | | | | (_| | |_) | (_| | || (__| | | |
// \____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_|____/ \__,_|\__\___|_| |_|
| ApiCommandFB.BatchFB, ParameterFB.TransactionFB ->
- either {
+ result {
let! commands =
let batchish = fb.Parameter()
if batchish.HasValue then
@@ -405,7 +412,7 @@ type ApiRequest =
else
"Empty CommandBatchFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (CommandBatch commands)
}
@@ -416,7 +423,7 @@ type ApiRequest =
// \____\__,_|\___|_| |_|\__,_|\__, |\___|_|
// |___/
| ApiCommandFB.AddFB, ParameterFB.CuePlayerFB ->
- either {
+ result {
let! player =
let playerish = fb.Parameter()
if playerish.HasValue then
@@ -425,11 +432,11 @@ type ApiRequest =
else
"Empty CuePlayer payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddCuePlayer player)
}
| ApiCommandFB.UpdateFB, ParameterFB.CuePlayerFB ->
- either {
+ result {
let! player =
let playerish = fb.Parameter()
if playerish.HasValue then
@@ -438,11 +445,11 @@ type ApiRequest =
else
"Empty CuePlayer payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateCuePlayer player)
}
| ApiCommandFB.RemoveFB, ParameterFB.CuePlayerFB ->
- either {
+ result {
let! player =
let playerish = fb.Parameter()
if playerish.HasValue then
@@ -451,7 +458,7 @@ type ApiRequest =
else
"Empty CuePlayer payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemoveCuePlayer player)
}
@@ -461,7 +468,7 @@ type ApiRequest =
// | |___| | | __/ | | | |_
// \____|_|_|\___|_| |_|\__|
| ApiCommandFB.AddFB, ParameterFB.DiscoClientFB ->
- either {
+ result {
let! client =
let clientish = fb.Parameter()
if clientish.HasValue then
@@ -470,11 +477,11 @@ type ApiRequest =
else
"Empty DiscoClientFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddClient client)
}
| ApiCommandFB.UpdateFB, ParameterFB.DiscoClientFB ->
- either {
+ result {
let! client =
let clientish = fb.Parameter()
if clientish.HasValue then
@@ -483,11 +490,11 @@ type ApiRequest =
else
"Empty DiscoClientFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateClient client)
}
| ApiCommandFB.RemoveFB, ParameterFB.DiscoClientFB ->
- either {
+ result {
let! client =
let clientish = fb.Parameter()
if clientish.HasValue then
@@ -496,7 +503,7 @@ type ApiRequest =
else
"Empty DiscoClientFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemoveClient client)
}
@@ -506,7 +513,7 @@ type ApiRequest =
// | | | | __/ | | | | | |_) | __/ |
// |_| |_|\___|_| |_| |_|_.__/ \___|_|
| ApiCommandFB.AddFB, ParameterFB.RaftMemberFB ->
- either {
+ result {
let! mem =
let memish = fb.Parameter()
if memish.HasValue then
@@ -515,11 +522,11 @@ type ApiRequest =
else
"Empty RaftMemberFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
- return ApiRequest.Update (AddMember mem)
+ |> Result.fail
+ return ApiRequest.Update (AddMachine mem)
}
| ApiCommandFB.UpdateFB, ParameterFB.RaftMemberFB ->
- either {
+ result {
let! mem =
let memish = fb.Parameter()
if memish.HasValue then
@@ -528,11 +535,11 @@ type ApiRequest =
else
"Empty RaftMemberFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
- return ApiRequest.Update (UpdateMember mem)
+ |> Result.fail
+ return ApiRequest.Update (UpdateMachine mem)
}
| ApiCommandFB.RemoveFB, ParameterFB.RaftMemberFB ->
- either {
+ result {
let! mem =
let memish = fb.Parameter()
if memish.HasValue then
@@ -541,7 +548,52 @@ type ApiRequest =
else
"Empty RaftMemberFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
+ return ApiRequest.Update (RemoveMachine mem)
+ }
+
+ // __ __ _
+ // | \/ | ___ _ __ ___ | |__ ___ _ __
+ // | |\/| |/ _ \ '_ ` _ \| '_ \ / _ \ '__|
+ // | | | | __/ | | | | | |_) | __/ |
+ // |_| |_|\___|_| |_| |_|_.__/ \___|_|
+ | ApiCommandFB.AddFB, ParameterFB.ClusterMemberFB ->
+ result {
+ let! mem =
+ let memish = fb.Parameter()
+ if memish.HasValue then
+ let value = memish.Value
+ ClusterMember.FromFB value
+ else
+ "Empty ClusterMemberFB payload"
+ |> Error.asParseError "ApiRequest.FromFB"
+ |> Result.fail
+ return ApiRequest.Update (AddMember mem)
+ }
+ | ApiCommandFB.UpdateFB, ParameterFB.ClusterMemberFB ->
+ result {
+ let! mem =
+ let memish = fb.Parameter()
+ if memish.HasValue then
+ let value = memish.Value
+ ClusterMember.FromFB value
+ else
+ "Empty ClusterMemberFB payload"
+ |> Error.asParseError "ApiRequest.FromFB"
+ |> Result.fail
+ return ApiRequest.Update (UpdateMember mem)
+ }
+ | ApiCommandFB.RemoveFB, ParameterFB.ClusterMemberFB ->
+ result {
+ let! mem =
+ let memish = fb.Parameter()
+ if memish.HasValue then
+ let value = memish.Value
+ ClusterMember.FromFB value
+ else
+ "Empty ClusterMemberFB payload"
+ |> Error.asParseError "ApiRequest.FromFB"
+ |> Result.fail
return ApiRequest.Update (RemoveMember mem)
}
@@ -552,15 +604,15 @@ type ApiRequest =
/// |_| |___/_____|_| |_|\__|_| \__, |
/// |___/
| ApiCommandFB.AddFB, ParameterFB.FsEntryUpdateFB ->
- either {
+ result {
let! entryUpdate =
let update = fb.Parameter()
if update.HasValue then
- Either.succeed update.Value
+ Result.succeed update.Value
else
"Empty FsEntryUpdateFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
let! id = Id.decodeHostId entryUpdate
let! entry =
let entryish = entryUpdate.Entry
@@ -570,19 +622,19 @@ type ApiRequest =
else
"Empty FsEntryFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddFsEntry (id, entry))
}
| ApiCommandFB.UpdateFB, ParameterFB.FsEntryUpdateFB ->
- either {
+ result {
let! entryUpdate =
let update = fb.Parameter()
if update.HasValue then
- Either.succeed update.Value
+ Result.succeed update.Value
else
"Empty FsEntryUpdateFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
let! id = Id.decodeHostId entryUpdate
let! entry =
let entryish = entryUpdate.Entry
@@ -592,19 +644,19 @@ type ApiRequest =
else
"Empty FsEntryFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateFsEntry (id, entry))
}
| ApiCommandFB.RemoveFB, ParameterFB.FsEntryUpdateFB ->
- either {
+ result {
let! entryUpdate =
let update = fb.Parameter()
if update.HasValue then
- Either.succeed update.Value
+ Result.succeed update.Value
else
"Empty FsEntryUpdateFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
let! id = Id.decodeHostId entryUpdate
let! path =
let entryish = entryUpdate.Path
@@ -614,7 +666,7 @@ type ApiRequest =
else
"Empty FsPathFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemoveFsEntry (id, path))
}
@@ -624,15 +676,15 @@ type ApiRequest =
/// | _|\__ \| || | | __/ __/
/// |_| |___/|_||_| \___|\___|
| ApiCommandFB.AddFB, ParameterFB.FsTreeUpdateFB ->
- either {
+ result {
let! treeUpdate =
let update = fb.Parameter()
if update.HasValue then
- Either.succeed update.Value
+ Result.succeed update.Value
else
"Empty FsTreeUpdateFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
let! tree =
let treeish = treeUpdate.Tree
@@ -642,19 +694,19 @@ type ApiRequest =
else
"Empty FsTreeFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddFsTree tree)
}
| ApiCommandFB.RemoveFB, ParameterFB.FsTreeUpdateFB ->
- either {
+ result {
let! treeUpdate =
let update = fb.Parameter()
if update.HasValue then
- Either.succeed update.Value
+ Result.succeed update.Value
else
"Empty FsTreeUpdateFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
let! id = Id.decodeHostId treeUpdate
return ApiRequest.Update (RemoveFsTree id)
}
@@ -666,7 +718,7 @@ type ApiRequest =
// \____|_| \___/ \__,_| .__/
// |_|
| ApiCommandFB.AddFB, ParameterFB.PinGroupFB ->
- either {
+ result {
let! group =
let groupish = fb.Parameter()
if groupish.HasValue then
@@ -675,11 +727,11 @@ type ApiRequest =
else
"Empty PinGroupFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddPinGroup group)
}
| ApiCommandFB.UpdateFB, ParameterFB.PinGroupFB ->
- either {
+ result {
let! group =
let groupish = fb.Parameter()
if groupish.HasValue then
@@ -688,11 +740,11 @@ type ApiRequest =
else
"Empty PinGroupFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdatePinGroup group)
}
| ApiCommandFB.RemoveFB, ParameterFB.PinGroupFB ->
- either {
+ result {
let! group =
let groupish = fb.Parameter()
if groupish.HasValue then
@@ -701,7 +753,7 @@ type ApiRequest =
else
"Empty PinGroupFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemovePinGroup group)
}
@@ -712,7 +764,7 @@ type ApiRequest =
// |_| |_|\__,_| .__/| .__/|_|_| |_|\__, |
// |_| |_| |___/
| ApiCommandFB.AddFB, ParameterFB.PinMappingFB ->
- either {
+ result {
let! mapping =
let mappingish = fb.Parameter()
if mappingish.HasValue then
@@ -721,11 +773,11 @@ type ApiRequest =
else
"Empty PinMappingFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddPinMapping mapping)
}
| ApiCommandFB.UpdateFB, ParameterFB.PinMappingFB ->
- either {
+ result {
let! mapping =
let mappingish = fb.Parameter()
if mappingish.HasValue then
@@ -734,11 +786,11 @@ type ApiRequest =
else
"Empty PinMappingFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdatePinMapping mapping)
}
| ApiCommandFB.RemoveFB, ParameterFB.PinMappingFB ->
- either {
+ result {
let! mapping =
let mappingish = fb.Parameter()
if mappingish.HasValue then
@@ -747,7 +799,7 @@ type ApiRequest =
else
"Empty PinMappingFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemovePinMapping mapping)
}
@@ -758,7 +810,7 @@ type ApiRequest =
// \_/\_/ |_|\__,_|\__, |\___|\__|
// |___/
| ApiCommandFB.AddFB, ParameterFB.PinWidgetFB ->
- either {
+ result {
let! widget =
let widgetish = fb.Parameter()
if widgetish.HasValue then
@@ -767,11 +819,11 @@ type ApiRequest =
else
"Empty PinWidgetFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddPinWidget widget)
}
| ApiCommandFB.UpdateFB, ParameterFB.PinWidgetFB ->
- either {
+ result {
let! widget =
let widgetish = fb.Parameter()
if widgetish.HasValue then
@@ -780,11 +832,11 @@ type ApiRequest =
else
"Empty PinWidgetFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdatePinWidget widget)
}
| ApiCommandFB.RemoveFB, ParameterFB.PinWidgetFB ->
- either {
+ result {
let! widget =
let widgetish = fb.Parameter()
if widgetish.HasValue then
@@ -793,7 +845,7 @@ type ApiRequest =
else
"Empty PinWidgetFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemovePinWidget widget)
}
@@ -803,7 +855,7 @@ type ApiRequest =
// | __/| | | | |
// |_| |_|_| |_|
| ApiCommandFB.AddFB, ParameterFB.PinFB ->
- either {
+ result {
let! pin =
let pinish = fb.Parameter()
if pinish.HasValue then
@@ -812,11 +864,11 @@ type ApiRequest =
else
"Empty PinFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddPin pin)
}
| ApiCommandFB.UpdateFB, ParameterFB.PinFB ->
- either {
+ result {
let! pin =
let pinish = fb.Parameter()
if pinish.HasValue then
@@ -825,11 +877,11 @@ type ApiRequest =
else
"Empty PinFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdatePin pin)
}
| ApiCommandFB.RemoveFB, ParameterFB.PinFB ->
- either {
+ result {
let! pin =
let pinish = fb.Parameter()
if pinish.HasValue then
@@ -838,11 +890,11 @@ type ApiRequest =
else
"Empty PinFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemovePin pin)
}
| ApiCommandFB.UpdateFB, ParameterFB.SlicesFB ->
- either {
+ result {
let! slices =
let slicish = fb.Parameter()
if slicish.HasValue then
@@ -851,7 +903,7 @@ type ApiRequest =
else
"Empty SlicesFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateSlices slices)
}
@@ -861,7 +913,7 @@ type ApiRequest =
// | |__| |_| | __/
// \____\__,_|\___|
| ApiCommandFB.AddFB, ParameterFB.CueFB ->
- either {
+ result {
let! cue =
let cueish = fb.Parameter()
if cueish.HasValue then
@@ -870,11 +922,11 @@ type ApiRequest =
else
"Empty CueFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddCue cue)
}
| ApiCommandFB.UpdateFB, ParameterFB.CueFB ->
- either {
+ result {
let! cue =
let cueish = fb.Parameter()
if cueish.HasValue then
@@ -883,11 +935,11 @@ type ApiRequest =
else
"Empty CueFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateCue cue)
}
| ApiCommandFB.RemoveFB, ParameterFB.CueFB ->
- either {
+ result {
let! cue =
let cueish = fb.Parameter()
if cueish.HasValue then
@@ -896,11 +948,11 @@ type ApiRequest =
else
"Empty CueFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemoveCue cue)
}
| ApiCommandFB.CallCueFB, ParameterFB.CueFB ->
- either {
+ result {
let! cue =
let cueish = fb.Parameter()
if cueish.HasValue then
@@ -909,7 +961,7 @@ type ApiRequest =
else
"Empty CueFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (CallCue cue)
}
@@ -919,7 +971,7 @@ type ApiRequest =
// | |__| |_| | __/ |___| \__ \ |_
// \____\__,_|\___|_____|_|___/\__|
| ApiCommandFB.AddFB, ParameterFB.CueListFB ->
- either {
+ result {
let! cueList =
let cueListish = fb.Parameter()
if cueListish.HasValue then
@@ -928,11 +980,11 @@ type ApiRequest =
else
"Empty CueListFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddCueList cueList)
}
| ApiCommandFB.UpdateFB, ParameterFB.CueListFB ->
- either {
+ result {
let! cueList =
let cueListish = fb.Parameter()
if cueListish.HasValue then
@@ -941,11 +993,11 @@ type ApiRequest =
else
"Empty CueListFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateCueList cueList)
}
| ApiCommandFB.RemoveFB, ParameterFB.CueListFB ->
- either {
+ result {
let! cueList =
let cueListish = fb.Parameter()
if cueListish.HasValue then
@@ -954,7 +1006,7 @@ type ApiRequest =
else
"Empty CueListFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemoveCueList cueList)
}
@@ -964,7 +1016,7 @@ type ApiRequest =
// | |_| \__ \ __/ |
// \___/|___/\___|_|
| ApiCommandFB.AddFB, ParameterFB.UserFB ->
- either {
+ result {
let! user =
let userish = fb.Parameter()
if userish.HasValue then
@@ -973,11 +1025,11 @@ type ApiRequest =
else
"Empty UserFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddUser user)
}
| ApiCommandFB.UpdateFB, ParameterFB.UserFB ->
- either {
+ result {
let! user =
let userish = fb.Parameter()
if userish.HasValue then
@@ -986,11 +1038,11 @@ type ApiRequest =
else
"Empty UserFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateUser user)
}
| ApiCommandFB.RemoveFB, ParameterFB.UserFB ->
- either {
+ result {
let! user =
let userish = fb.Parameter()
if userish.HasValue then
@@ -999,7 +1051,7 @@ type ApiRequest =
else
"Empty UserFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemoveUser user)
}
@@ -1009,7 +1061,7 @@ type ApiRequest =
// ___) | __/\__ \__ \ | (_) | | | |
// |____/ \___||___/___/_|\___/|_| |_|
| ApiCommandFB.AddFB, ParameterFB.SessionFB ->
- either {
+ result {
let! session =
let sessionish = fb.Parameter()
if sessionish.HasValue then
@@ -1018,11 +1070,11 @@ type ApiRequest =
else
"Empty SessionFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddSession session)
}
| ApiCommandFB.UpdateFB, ParameterFB.SessionFB ->
- either {
+ result {
let! session =
let sessionish = fb.Parameter()
if sessionish.HasValue then
@@ -1031,11 +1083,11 @@ type ApiRequest =
else
"Empty SessionFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateSession session)
}
| ApiCommandFB.RemoveFB, ParameterFB.SessionFB ->
- either {
+ result {
let! session =
let sessionish = fb.Parameter()
if sessionish.HasValue then
@@ -1044,7 +1096,7 @@ type ApiRequest =
else
"Empty SessionFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemoveSession session)
}
@@ -1054,7 +1106,7 @@ type ApiRequest =
// | |_| | \__ \ (_| (_) \ V / __/ | | __/ (_| |
// |____/|_|___/\___\___/ \_/ \___|_| \___|\__,_|
| ApiCommandFB.AddFB, ParameterFB.DiscoveredServiceFB ->
- either {
+ result {
let! service =
let serviceish = fb.Parameter()
if serviceish.HasValue then
@@ -1063,11 +1115,11 @@ type ApiRequest =
else
"Empty DiscoveredServiceFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (AddDiscoveredService service)
}
| ApiCommandFB.UpdateFB, ParameterFB.DiscoveredServiceFB ->
- either {
+ result {
let! service =
let serviceish = fb.Parameter()
if serviceish.HasValue then
@@ -1076,11 +1128,11 @@ type ApiRequest =
else
"Empty DiscoveredServiceFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateDiscoveredService service)
}
| ApiCommandFB.RemoveFB, ParameterFB.DiscoveredServiceFB ->
- either {
+ result {
let! service =
let serviceish = fb.Parameter()
if serviceish.HasValue then
@@ -1089,7 +1141,7 @@ type ApiRequest =
else
"Empty DiscoveredServiceFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (RemoveDiscoveredService service)
}
@@ -1100,7 +1152,7 @@ type ApiRequest =
// |_____\___/ \__, |
// |___/
| ApiCommandFB.LogEventFB, ParameterFB.LogEventFB ->
- either {
+ result {
let! log =
let logish = fb.Parameter()
if logish.HasValue then
@@ -1109,11 +1161,11 @@ type ApiRequest =
else
"Empty LogEventFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (LogMsg log)
}
| ApiCommandFB.SetLogLevelFB, _ ->
- either {
+ result {
let! level =
let levelish = fb.Parameter()
if levelish.HasValue then
@@ -1122,7 +1174,7 @@ type ApiRequest =
else
"Empty StringFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (SetLogLevel level)
}
@@ -1132,16 +1184,16 @@ type ApiRequest =
// | |___| | (_) | (__| <
// \____|_|\___/ \___|_|\_\
| ApiCommandFB.UpdateFB, ParameterFB.ClockFB ->
- either {
+ result {
let! clock =
let clockish = fb.Parameter()
if clockish.HasValue then
let value = clockish.Value
- Right value.Value
+ Ok value.Value
else
"Empty ClockFB payload"
|> Error.asParseError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
return ApiRequest.Update (UpdateClock clock)
}
@@ -1154,24 +1206,24 @@ type ApiRequest =
AppCommand.Undo
|> Command
|> ApiRequest.Update
- |> Either.succeed
+ |> Result.succeed
| ApiCommandFB.RedoFB, _ ->
AppCommand.Redo
|> Command
|> ApiRequest.Update
- |> Either.succeed
+ |> Result.succeed
| ApiCommandFB.ResetFB, _ ->
AppCommand.Reset
|> Command
|> ApiRequest.Update
- |> Either.succeed
+ |> Result.succeed
| x,y ->
sprintf "Unknown Command/Type combination in ApiRequest: %A/%A" x y
|> Error.asClientError "ApiRequest.FromFB"
- |> Either.fail
+ |> Result.fail
// ** ToBytes
@@ -1219,10 +1271,10 @@ type ApiResponse =
static member FromFB(fb: ApiResponseFB) =
match fb.Status with
- | StatusFB.RegisteredFB -> Right Registered
- | StatusFB.UnregisteredFB -> Right Unregistered
+ | StatusFB.RegisteredFB -> Ok Registered
+ | StatusFB.UnregisteredFB -> Ok Unregistered
| StatusFB.NOKFB ->
- either {
+ result {
let! error =
let errorish = fb.Error
if errorish.HasValue then
@@ -1231,13 +1283,13 @@ type ApiResponse =
else
"Empty ApiErrorFB value"
|> Error.asParseError "ApiResponse.FromFB"
- |> Either.fail
+ |> Result.fail
return NOK error
}
| x ->
sprintf "Unknown StatusFB value: %A" x
|> Error.asParseError "ApiResponse.FromFB"
- |> Either.fail
+ |> Result.fail
member request.ToBytes() =
Binary.buildBuffer request
diff --git a/src/Disco/Disco/Client/Interfaces.fs b/src/Disco/Disco/Client/Interfaces.fs
index 4f98f1d2..1cd70341 100644
--- a/src/Disco/Disco/Client/Interfaces.fs
+++ b/src/Disco/Disco/Client/Interfaces.fs
@@ -50,8 +50,8 @@ type ClientEvent =
type IApiClient =
inherit IDisposable
abstract Id: ClientId
- abstract Start: unit -> Either
- abstract Restart: server:DiscoServer -> Either
+ abstract Start: unit -> DiscoResult
+ abstract Restart: server:DiscoServer -> DiscoResult
abstract State: State
abstract Status: ServiceStatus
abstract Subscribe: (ClientEvent -> unit) -> IDisposable
diff --git a/src/Disco/Disco/Core/Actor.fs b/src/Disco/Disco/Core/Actor.fs
index 96d2dfd2..da8c683e 100644
--- a/src/Disco/Disco/Core/Actor.fs
+++ b/src/Disco/Disco/Core/Actor.fs
@@ -70,7 +70,7 @@ module AsyncActor =
// ** loop
- let private loop<'a> tag actor (f: AsyncActorTask<'a>) (inbox: MailboxProcessor<'a>) =
+ let private loop<'a> _ actor (f: AsyncActorTask<'a>) (inbox: MailboxProcessor<'a>) =
let rec _loop () =
async {
let! msg = inbox.Receive()
@@ -112,7 +112,7 @@ module ThreadActor =
// ** loop
- let private loop<'a> tag (queue: Queue<'a>) (actor: IActor<'a>) (f: ActorTask<'a>) () =
+ let private loop<'a> _ (queue: Queue<'a>) (actor: IActor<'a>) (f: ActorTask<'a>) () =
let mutable run = true
try
while run do
diff --git a/src/Disco/Disco/Core/Aliases.fs b/src/Disco/Disco/Core/Aliases.fs
index 6a55f656..da249b34 100644
--- a/src/Disco/Disco/Core/Aliases.fs
+++ b/src/Disco/Disco/Core/Aliases.fs
@@ -101,8 +101,6 @@ module Measure =
let email e: Email = UoM.wrap e
let port p: Port = UoM.wrap p
let checksum t: Hash = UoM.wrap t
- let index i: Index = i * 1
- let term t: Term = t * 1
let version v: Version = UoM.wrap v
let astag t: Tag = UoM.wrap t
let url t: Url = UoM.wrap t
@@ -243,59 +241,59 @@ type ServiceStatus =
// ** FromFB
static member FromFB (fb: ServiceStatusFB) =
- either {
+ result {
return!
#if FABLE_COMPILER
match fb.Type with
- | x when x = ServiceStatusTypeFB.RunningFB -> Right Running
- | x when x = ServiceStatusTypeFB.StartingFB -> Right Starting
- | x when x = ServiceStatusTypeFB.StoppingFB -> Right Stopping
- | x when x = ServiceStatusTypeFB.StoppedFB -> Right Stopped
- | x when x = ServiceStatusTypeFB.DisposedFB -> Right Disposed
+ | x when x = ServiceStatusTypeFB.RunningFB -> Ok Running
+ | x when x = ServiceStatusTypeFB.StartingFB -> Ok Starting
+ | x when x = ServiceStatusTypeFB.StoppingFB -> Ok Stopping
+ | x when x = ServiceStatusTypeFB.StoppedFB -> Ok Stopped
+ | x when x = ServiceStatusTypeFB.DisposedFB -> Ok Disposed
| x when x = ServiceStatusTypeFB.DegradedFB ->
- fb.Error |> DiscoError.FromFB |> Either.map Degraded
+ fb.Error |> DiscoError.FromFB |> Result.map Degraded
| x when x = ServiceStatusTypeFB.FailedFB ->
- fb.Error |> DiscoError.FromFB |> Either.map Failed
+ fb.Error |> DiscoError.FromFB |> Result.map Failed
| other ->
other
|> sprintf "could not parse empty Error payload: %O"
|> Error.asParseError "ServiceStatus.FromFB"
- |> Either.fail
+ |> Result.fail
#else
match fb.Type with
- | ServiceStatusTypeFB.RunningFB -> Right Running
- | ServiceStatusTypeFB.StartingFB -> Right Starting
- | ServiceStatusTypeFB.StoppingFB -> Right Stopping
- | ServiceStatusTypeFB.StoppedFB -> Right Stopped
- | ServiceStatusTypeFB.DisposedFB -> Right Disposed
+ | ServiceStatusTypeFB.RunningFB -> Ok Running
+ | ServiceStatusTypeFB.StartingFB -> Ok Starting
+ | ServiceStatusTypeFB.StoppingFB -> Ok Stopping
+ | ServiceStatusTypeFB.StoppedFB -> Ok Stopped
+ | ServiceStatusTypeFB.DisposedFB -> Ok Disposed
| ServiceStatusTypeFB.DegradedFB ->
let valueish = fb.Error
if valueish.HasValue then
let value = valueish.Value
DiscoError.FromFB value
- |> Either.map Degraded
+ |> Result.map Degraded
else
"could not parse empty Error payload"
|> Error.asParseError "ServiceStatus.FromFB"
- |> Either.fail
+ |> Result.fail
| ServiceStatusTypeFB.FailedFB ->
let valueish = fb.Error
if valueish.HasValue then
let value = valueish.Value
DiscoError.FromFB value
- |> Either.map Failed
+ |> Result.map Failed
else
"could not parse empty Error payload"
|> Error.asParseError "ServiceStatus.FromFB"
- |> Either.fail
+ |> Result.fail
| other ->
other
|> sprintf "could not parse empty Error payload: %O"
|> Error.asParseError "ServiceStatus.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
}
diff --git a/src/Disco/Disco/Core/Asset.fs b/src/Disco/Disco/Core/Asset.fs
index efe9ec40..a26fb416 100644
--- a/src/Disco/Disco/Core/Asset.fs
+++ b/src/Disco/Disco/Core/Asset.fs
@@ -35,46 +35,46 @@ module Asset =
#if !FABLE_COMPILER
- let inline save< ^t when ^t : (member Save: FilePath -> Either)>
+ let inline save< ^t when ^t : (member Save: FilePath -> DiscoResult)>
(path: FilePath)
(t: ^t) =
- (^t : (member Save: FilePath -> Either) (t, path))
+ (^t : (member Save: FilePath -> DiscoResult) (t, path))
// ** delete
- let inline delete< ^t when ^t : (member Delete: FilePath -> Either)>
+ let inline delete< ^t when ^t : (member Delete: FilePath -> DiscoResult)>
(path: FilePath)
(t: ^t) =
- (^t : (member Delete: FilePath -> Either) (t, path))
+ (^t : (member Delete: FilePath -> DiscoResult) (t, path))
// ** saveMap
- let inline saveMap (basepath: FilePath) (guard: Either) _ (t: ^t) =
- either {
+ let inline saveMap (basepath: FilePath) (guard: DiscoResult) _ (t: ^t) =
+ result {
do! guard
do! save basepath t
}
// ** load
- let inline load< ^t when ^t : (static member Load: FilePath -> Either)>
+ let inline load< ^t when ^t : (static member Load: FilePath -> DiscoResult< ^t>)>
(path: FilePath) =
- (^t : (static member Load: FilePath -> Either) path)
+ (^t : (static member Load: FilePath -> DiscoResult< ^t>) path)
// ** loadWithMachine
- let inline loadWithMachine< ^t when ^t : (static member Load: FilePath * DiscoMachine -> Either)>
+ let inline loadWithMachine< ^t when ^t : (static member Load: FilePath * DiscoMachine -> DiscoResult< ^t>)>
(path: FilePath)
(machine: DiscoMachine) =
- (^t : (static member Load: FilePath * DiscoMachine -> Either) (path,machine))
+ (^t : (static member Load: FilePath * DiscoMachine -> DiscoResult< ^t>) (path,machine))
// ** loadAll
- let inline loadAll< ^t when ^t : (static member LoadAll: FilePath -> Either)>
+ let inline loadAll< ^t when ^t : (static member LoadAll: FilePath -> DiscoResult< ^t array>)>
(basePath: FilePath) =
- (^t : (static member LoadAll: FilePath -> Either) basePath)
+ (^t : (static member LoadAll: FilePath -> DiscoResult< ^t array>) basePath)
// ** hasParent
@@ -104,9 +104,9 @@ module DiscoData =
/// - location: FilePath to asset
/// - payload: string payload to save
///
- /// Returns: Either
+ /// Returns: DiscoResult
let write (location: FilePath) (payload: StringPayload) =
- either {
+ result {
try
let data = match payload with | Payload data -> data
let info = File.info location
@@ -119,7 +119,7 @@ module DiscoData =
return!
exn.Message
|> Error.asAssetError (tag "write")
- |> Either.fail
+ |> Result.fail
}
#endif
@@ -135,9 +135,9 @@ module DiscoData =
/// ### Signature:
/// - location: FilePath to asset
///
- /// Returns: Either
+ /// Returns: DiscoResult
let remove (location: FilePath) =
- either {
+ result {
try
if File.exists location then
Path.map File.Delete location
@@ -148,7 +148,7 @@ module DiscoData =
return!
exn.Message
|> Error.asAssetError (tag "remove")
- |> Either.fail
+ |> Result.fail
}
#endif
@@ -165,9 +165,9 @@ module DiscoData =
/// ### Signature:
/// - locationg: FilePath to asset
///
- /// Returns: Either
- let read (location: FilePath) : Either =
- either {
+ /// Returns: DiscoResult
+ let read (location: FilePath) : DiscoResult< string> =
+ result {
if File.exists location then
try
return File.readText location
@@ -176,19 +176,19 @@ module DiscoData =
return!
exn.Message
|> Error.asAssetError (tag "read")
- |> Either.fail
+ |> Result.fail
else
return!
sprintf "File not found: %O" location
|> Error.asAssetError (tag "read")
- |> Either.fail
+ |> Result.fail
}
#endif
// ** load
let inline load (path: FilePath) =
- either {
+ result {
let! data = read path
let! group = Yaml.decode data
return group
@@ -197,7 +197,7 @@ module DiscoData =
// ** loadAll
let inline loadAll (basePath: FilePath) =
- either {
+ result {
try
let files = Directory.getFiles true ("*" + Constants.ASSET_EXTENSION) basePath
let! (_,groups) =
@@ -206,14 +206,14 @@ module DiscoData =
|> Array.length
|> Array.zeroCreate
Array.fold
- (fun (m: Either) path ->
- either {
+ (fun (m: DiscoResult) path ->
+ result {
let! (idx,groups) = m
let! group = load path
groups.[idx] <- group
return (idx + 1, groups)
})
- (Right(0, arr))
+ (Ok(0, arr))
files
return groups
with
@@ -221,7 +221,7 @@ module DiscoData =
return!
exn.Message
|> Error.asAssetError "PinGroup.LoadAll"
- |> Either.fail
+ |> Result.fail
}
// ** ensureDirectoryExists
@@ -231,9 +231,9 @@ module DiscoData =
path
|> Path.getDirectoryName
|> Directory.createDirectory
- |> Either.ignore
+ |> Result.ignore
else
- Either.nothing
+ Result.nothing
// ** ensureDirectoryGone
@@ -241,14 +241,14 @@ module DiscoData =
if Asset.hasParent asset then
if Directory.isEmpty dir then
Directory.removeDirectory dir
- |> Either.ignore
- else Either.nothing
- else Either.nothing
+ |> Result.ignore
+ else Result.nothing
+ else Result.nothing
// ** save
let inline save (basePath: FilePath) asset =
- either {
+ result {
let path = basePath > Asset.path asset
do! ensureDirectoryExists path asset
let data = Yaml.encode asset
@@ -259,7 +259,7 @@ module DiscoData =
// ** delete
let inline delete (basePath: FilePath) asset =
- either {
+ result {
let path = basePath > Asset.path asset
do! path |> Path.concat basePath |> remove
do! ensureDirectoryGone (Path.directoryName path) asset
@@ -270,7 +270,7 @@ module DiscoData =
#if !FABLE_COMPILER
let inline commit (basepath: FilePath) (msg: string) (signature: LibGit2Sharp.Signature) (t: ^t) =
- either {
+ result {
use! repo = Git.Repo.repository basepath
let target =
@@ -291,7 +291,7 @@ module DiscoData =
#if !FABLE_COMPILER
let inline saveWithCommit (basepath: FilePath) (signature: LibGit2Sharp.Signature) (t: ^t) =
- either {
+ result {
do! save basepath t
let filename = t |> Asset.path |> Path.getFileName
let msg = sprintf "%s saved %A" signature.Name filename
@@ -305,7 +305,7 @@ module DiscoData =
#if !FABLE_COMPILER
let inline deleteWithCommit (basepath: FilePath) (signature: LibGit2Sharp.Signature) (t: ^t) =
- either {
+ result {
let filepath = basepath > Asset.path t
let! _ = remove filepath
let msg = sprintf "%s deleted %A" signature.Name (Path.getFileName filepath)
diff --git a/src/Disco/Disco/Core/Client.fs b/src/Disco/Disco/Core/Client.fs
index 76abd918..83fb6eda 100644
--- a/src/Disco/Disco/Core/Client.fs
+++ b/src/Disco/Disco/Core/Client.fs
@@ -43,18 +43,18 @@ type Role =
static member FromFB(fb: RoleFB) =
#if FABLE_COMPILER
match fb with
- | x when x = RoleFB.RendererFB -> Either.succeed Renderer
+ | x when x = RoleFB.RendererFB -> Result.succeed Renderer
| x ->
sprintf "Unknown RoleFB value: %A" x
|> Error.asClientError "Role.FromFB"
- |> Either.fail
+ |> Result.fail
#else
match fb with
- | RoleFB.RendererFB -> Either.succeed Renderer
+ | RoleFB.RendererFB -> Result.succeed Renderer
| x ->
sprintf "Unknown RoleFB value: %A" x
|> Error.asClientError "Role.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
// * DiscoClient
@@ -97,7 +97,7 @@ type DiscoClient =
// ** FromFB
static member FromFB(fb: DiscoClientFB) =
- either {
+ result {
let! id = Id.decodeId fb
let! serviceId = Id.decodeServiceId fb
let! role = Role.FromFB fb.Role
@@ -113,7 +113,7 @@ type DiscoClient =
else
"could not parse empty status payload"
|> Error.asParseError "DiscoClient.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
return {
Id = id
diff --git a/src/Disco/Disco/Core/Color.fs b/src/Disco/Disco/Core/Color.fs
index 63a31936..1513cea4 100644
--- a/src/Disco/Disco/Core/Color.fs
+++ b/src/Disco/Disco/Core/Color.fs
@@ -148,17 +148,17 @@ type RGBAValue =
Green = green
Blue = blue
Alpha = alpha }
- |> Either.succeed
+ |> Result.succeed
| Parsing.RGB (red, green, blue) ->
{ Red = red
Green = green
Blue = blue
Alpha = 255uy }
- |> Either.succeed
+ |> Result.succeed
| _ ->
System.String.Format("Cannot parse {0} as RGB(A)", value)
|> Error.asParseError "RGBAValue.TryParse"
- |> Either.fail
+ |> Result.fail
// ** ToOffset
@@ -179,18 +179,18 @@ type RGBAValue =
// ** FromFB
- static member FromFB(fb: RGBAValueFB) : Either =
+ static member FromFB(fb: RGBAValueFB) : DiscoResult =
try
{ Red = fb.Red
; Green = fb.Green
; Blue = fb.Blue
; Alpha = fb.Alpha
- } |> Right
+ } |> Ok
with
| exn ->
exn.Message
|> Error.asParseError "RGBAValue.FromFB"
- |> Either.fail
+ |> Result.fail
// ** ToBytes
@@ -291,18 +291,18 @@ type HSLAValue =
// ** FromFB
- static member FromFB(fb: HSLAValueFB) : Either =
+ static member FromFB(fb: HSLAValueFB) : DiscoResult =
try
{ Hue = fb.Hue
; Saturation = fb.Saturation
; Lightness = fb.Lightness
; Alpha = fb.Alpha
- } |> Right
+ } |> Ok
with
| exn ->
exn.Message
|> Error.asParseError "HSLAValue.FromFB"
- |> Either.fail
+ |> Result.fail
// ** ToBytes
@@ -333,7 +333,7 @@ type ColorSpace =
static member TryParse(value:string) =
value
|> RGBAValue.TryParse
- |> Either.map ColorSpace.RGBA
+ |> Result.map ColorSpace.RGBA
// ** Black
@@ -372,25 +372,25 @@ type ColorSpace =
// ** FromFB
- static member FromFB(fb: ColorSpaceFB) : Either =
+ static member FromFB(fb: ColorSpaceFB) : DiscoResult =
#if FABLE_COMPILER
match fb.ValueType with
| x when x = ColorSpaceTypeFB.RGBAValueFB ->
RGBAValueFB.Create()
|> fb.Value
|> RGBAValue.FromFB
- |> Either.map RGBA
+ |> Result.map RGBA
| x when x = ColorSpaceTypeFB.HSLAValueFB ->
HSLAValueFB.Create()
|> fb.Value
|> HSLAValue.FromFB
- |> Either.map HSLA
+ |> Result.map HSLA
| x ->
sprintf "Could not deserialize %A" x
|> Error.asParseError "ColorSpace.FromFB"
- |> Either.fail
+ |> Result.fail
#else
// On .NET side, System.Nullables are used. Hard to emulate rn.
@@ -400,27 +400,27 @@ type ColorSpace =
if v.HasValue then
v.Value
|> RGBAValue.FromFB
- |> Either.map RGBA
+ |> Result.map RGBA
else
"Could not parse RGBAValue"
|> Error.asParseError "ColorSpace.FromFB"
- |> Either.fail
+ |> Result.fail
| ColorSpaceTypeFB.HSLAValueFB ->
let v = fb.Value()
if v.HasValue then
v.Value
|> HSLAValue.FromFB
- |> Either.map HSLA
+ |> Result.map HSLA
else
"Could not parse RGBAValue"
|> Error.asParseError "ColorSpace.FromFB"
- |> Either.fail
+ |> Result.fail
| x ->
sprintf "Could not parse ColorSpaceFB. Unknown type: %A" x
|> Error.asParseError "ColorSpace.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
@@ -469,17 +469,17 @@ type ColorSpace =
Green = yml.Channel2;
Blue = yml.Channel3;
Alpha = yml.Alpha
- } |> Right
+ } |> Ok
| "HSLA" ->
HSLA {
Hue = yml.Channel1;
Saturation = yml.Channel2;
Lightness = yml.Channel3;
Alpha = yml.Alpha
- } |> Right
+ } |> Ok
| x ->
sprintf "Could not parse ColorYaml. Unknown type: %s" x
|> Error.asParseError "ColorSpace.FromYaml"
- |> Either.fail
+ |> Result.fail
#endif
diff --git a/src/Disco/Disco/Core/Commands.fs b/src/Disco/Disco/Core/Commands.fs
index 86add673..e69abe0e 100644
--- a/src/Disco/Disco/Core/Commands.fs
+++ b/src/Disco/Disco/Core/Commands.fs
@@ -43,4 +43,4 @@ type Command =
| LoadProject of projectName:Name * site:NameAndId option
| GetProjectSites of projectName:Name
-type CommandAgent = Command -> Async>
+type CommandAgent = Command -> Async>
diff --git a/src/Disco/Disco/Core/Cue.fs b/src/Disco/Disco/Core/Cue.fs
index 7996d1af..772af402 100644
--- a/src/Disco/Disco/Core/Cue.fs
+++ b/src/Disco/Disco/Core/Cue.fs
@@ -50,19 +50,19 @@ type CueYaml() =
// ** ToCue
member yaml.ToCue() =
- either {
+ result {
let! slices =
let arr = Array.zeroCreate yaml.Slices.Length
Array.fold
- (fun (m: Either) box -> either {
+ (fun (m: DiscoResult) box -> result {
let! (i, arr) = m
let! (slice : Slices) = Yaml.fromYaml box
arr.[i] <- slice
return (i + 1, arr)
})
- (Right (0, arr))
+ (Ok (0, arr))
yaml.Slices
- |> Either.map snd
+ |> Result.map snd
let! id = DiscoId.TryParse yaml.Id
@@ -106,12 +106,12 @@ type Cue =
// |____/|_|_| |_|\__,_|_| \__, |
// |___/
- static member FromFB(fb: CueFB) : Either =
- either {
+ static member FromFB(fb: CueFB) : DiscoResult =
+ result {
let! slices =
let arr = Array.zeroCreate fb.SlicesLength
Array.fold
- (fun (m: Either) _ -> either {
+ (fun (m: DiscoResult) _ -> result {
let! (i, slices) = m
let! slice =
@@ -126,19 +126,19 @@ type Cue =
else
"Could not parse empty SlicesFB"
|> Error.asParseError "Cue.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
with
| exn ->
exn.Message
|> Error.asParseError "Cue.FromtFB"
- |> Either.fail
+ |> Result.fail
slices.[i] <- slice
return (i + 1, slices) })
- (Right (0, arr))
+ (Ok (0, arr))
arr
- |> Either.map snd
+ |> Result.map snd
let! id = Id.decodeId fb
@@ -164,7 +164,7 @@ type Cue =
// ** FromBytes
- static member FromBytes(bytes: byte[]) : Either =
+ static member FromBytes(bytes: byte[]) : DiscoResult =
bytes
|> Binary.createBuffer
|> CueFB.GetRootAsCueFB
@@ -188,7 +188,7 @@ type Cue =
// ** FromYaml
- static member FromYaml(yaml: CueYaml) : Either =
+ static member FromYaml(yaml: CueYaml) : DiscoResult =
yaml.ToCue()
// ** AssetPath
@@ -216,12 +216,12 @@ type Cue =
// | |__| (_) | (_| | (_| |
// |_____\___/ \__,_|\__,_|
- static member Load(path: FilePath) : Either =
+ static member Load(path: FilePath) : DiscoResult =
DiscoData.load path
// ** LoadAll
- static member LoadAll(basePath: FilePath) : Either =
+ static member LoadAll(basePath: FilePath) : DiscoResult =
basePath > filepath CUE_DIR
|> DiscoData.loadAll
diff --git a/src/Disco/Disco/Core/CueGroup.fs b/src/Disco/Disco/Core/CueGroup.fs
index c8dd7a32..fba08187 100644
--- a/src/Disco/Disco/Core/CueGroup.fs
+++ b/src/Disco/Disco/Core/CueGroup.fs
@@ -53,9 +53,9 @@ type CueGroupYaml() =
// ** ToCueGroup
member yaml.ToCueGroup() =
- either {
+ result {
let! id = DiscoId.TryParse yaml.Id
- let! cues = Either.bindArray Yaml.fromYaml yaml.CueRefs
+ let! cues = Result.bindArray Yaml.fromYaml yaml.CueRefs
let name =
if System.String.IsNullOrWhiteSpace yaml.Name
then None
@@ -106,10 +106,10 @@ type CueGroup =
// |____/|_|_| |_|\__,_|_| \__, |
// |___/
- static member FromFB(fb: CueGroupFB) : Either =
- either {
+ static member FromFB(fb: CueGroupFB) : DiscoResult =
+ result {
let! cues =
- EitherExt.bindGeneratorToArray
+ ResultExt.bindGeneratorToArray
"CueGroup.FromFB"
fb.CueRefsLength
fb.CueRefs
@@ -143,7 +143,7 @@ type CueGroup =
// ** FromBytes
- static member FromBytes(bytes: byte[]) : Either =
+ static member FromBytes(bytes: byte[]) : DiscoResult =
bytes
|> Binary.createBuffer
|> CueGroupFB.GetRootAsCueGroupFB
@@ -167,7 +167,7 @@ type CueGroup =
// ** FromYaml
- static member FromYaml(yaml: CueGroupYaml) : Either =
+ static member FromYaml(yaml: CueGroupYaml) : DiscoResult =
yaml.ToCueGroup()
#endif
diff --git a/src/Disco/Disco/Core/CueList.fs b/src/Disco/Disco/Core/CueList.fs
index c60b784d..3abda8fc 100644
--- a/src/Disco/Disco/Core/CueList.fs
+++ b/src/Disco/Disco/Core/CueList.fs
@@ -45,19 +45,19 @@ type CueListYaml() =
yaml
member yaml.ToCueList() =
- either {
+ result {
let! items =
let arr = Array.zeroCreate yaml.Items.Length
Array.fold
- (fun (m: Either) itemish -> either {
+ (fun (m: DiscoResult) itemish -> result {
let! (i, arr) = m
let! (item: CueGroup) = Yaml.fromYaml itemish
arr.[i] <- item
return (i + 1, arr)
})
- (Right (0, arr))
+ (Ok (0, arr))
yaml.Items
- |> Either.map snd
+ |> Result.map snd
let! id = DiscoId.TryParse yaml.Id
@@ -122,12 +122,12 @@ type CueList =
// ** FromFB
- static member FromFB(fb: CueListFB) : Either =
- either {
+ static member FromFB(fb: CueListFB) : DiscoResult =
+ result {
let! items =
let arr = Array.zeroCreate fb.ItemsLength
Array.fold
- (fun (m: Either) _ -> either {
+ (fun (m: DiscoResult) _ -> result {
let! (i, items) = m
#if FABLE_COMPILER
@@ -140,15 +140,15 @@ type CueList =
else
"Could not parse empty CueGroupFB"
|> Error.asParseError "CueList.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
items.[i] <- item
return (i + 1, items)
})
- (Right (0, arr))
+ (Ok (0, arr))
arr
- |> Either.map snd
+ |> Result.map snd
let! id = Id.decodeId fb
@@ -180,7 +180,7 @@ type CueList =
// ** FromYaml
- static member FromYaml(yml: CueListYaml) : Either =
+ static member FromYaml(yml: CueListYaml) : DiscoResult =
yml.ToCueList()
// ** AssetPath
@@ -202,12 +202,12 @@ type CueList =
// | |__| (_) | (_| | (_| |
// |_____\___/ \__,_|\__,_|
- static member Load(path: FilePath) : Either =
+ static member Load(path: FilePath) : DiscoResult =
DiscoData.load path
// ** LoadAll
- static member LoadAll(basePath: FilePath) : Either =
+ static member LoadAll(basePath: FilePath) : DiscoResult =
basePath > filepath CUELIST_DIR
|> DiscoData.loadAll
diff --git a/src/Disco/Disco/Core/CuePlayer.fs b/src/Disco/Disco/Core/CuePlayer.fs
index 6605188f..f471b5e1 100644
--- a/src/Disco/Disco/Core/CuePlayer.fs
+++ b/src/Disco/Disco/Core/CuePlayer.fs
@@ -68,7 +68,7 @@ type CuePlayerYaml() =
// ** ToPlayer
member yaml.ToPlayer() =
- either {
+ result {
let str2opt str =
match str with
| null -> None
@@ -83,7 +83,7 @@ type CuePlayerYaml() =
Locked = yaml.Locked
Active = yaml.Active
CueListId = str2opt yaml.CueListId
- Selected = index yaml.Selected
+ Selected = 1 * yaml.Selected
CallId = call
NextId = next
PreviousId = previous
@@ -200,30 +200,30 @@ type CuePlayer =
// ** FromFB
static member FromFB(fb: CuePlayerFB) =
- either {
+ result {
let! cuelist =
try
if fb.CueListIdLength = 0
- then Either.succeed None
- else Id.decodeCueListId fb |> Either.map Some
+ then Result.succeed None
+ else Id.decodeCueListId fb |> Result.map Some
with exn ->
- Either.succeed None
+ Result.succeed None
let! lastcalled =
try
if fb.LastCalledIdLength = 0
- then Either.succeed None
- else Id.decodeLastCalledId fb |> Either.map Some
+ then Result.succeed None
+ else Id.decodeLastCalledId fb |> Result.map Some
with exn ->
- Either.succeed None
+ Result.succeed None
let! lastcaller =
try
if fb.LastCallerIdLength = 0
- then Either.succeed None
- else Id.decodeLastCallerId fb |> Either.map Some
+ then Result.succeed None
+ else Id.decodeLastCallerId fb |> Result.map Some
with exn ->
- Either.succeed None
+ Result.succeed None
let! id = Id.decodeId fb
let! call = Id.decodeCallId fb
@@ -235,7 +235,7 @@ type CuePlayer =
Name = name fb.Name
Locked = fb.Locked
Active = fb.Active
- Selected = index fb.Selected
+ Selected = 1 * fb.Selected
RemainingWait = fb.RemainingWait
CueListId = cuelist
CallId = call
@@ -252,7 +252,7 @@ type CuePlayer =
// ** FromBytes
- static member FromBytes (bytes: byte[]) : Either =
+ static member FromBytes (bytes: byte[]) : DiscoResult =
Binary.createBuffer bytes
|> CuePlayerFB.GetRootAsCuePlayerFB
|> CuePlayer.FromFB
@@ -278,12 +278,12 @@ type CuePlayer =
#if !FABLE_COMPILER && !DISCO_NODES
- static member Load(path: FilePath) : Either =
+ static member Load(path: FilePath) : DiscoResult =
DiscoData.load path
// ** LoadAll
- static member LoadAll(basePath: FilePath) : Either =
+ static member LoadAll(basePath: FilePath) : DiscoResult =
basePath > filepath Constants.CUEPLAYER_DIR
|> DiscoData.loadAll
diff --git a/src/Disco/Disco/Core/CueReference.fs b/src/Disco/Disco/Core/CueReference.fs
index f9da48b0..43685bc2 100644
--- a/src/Disco/Disco/Core/CueReference.fs
+++ b/src/Disco/Disco/Core/CueReference.fs
@@ -55,7 +55,7 @@ type CueReferenceYaml() =
// ** ToCueReference
member yaml.ToCueReference() =
- either {
+ result {
let! id = DiscoId.TryParse yaml.Id
let! cueId = DiscoId.TryParse yaml.CueId
return {
@@ -112,8 +112,8 @@ type CueReference =
// |____/|_|_| |_|\__,_|_| \__, |
// |___/
- static member FromFB(fb: CueReferenceFB) : Either =
- either {
+ static member FromFB(fb: CueReferenceFB) : DiscoResult =
+ result {
let! id = Id.decodeId fb
let! cueId = Id.decodeCueId fb
return {
@@ -140,7 +140,7 @@ type CueReference =
// ** FromBytes
- static member FromBytes(bytes: byte[]) : Either =
+ static member FromBytes(bytes: byte[]) : DiscoResult =
bytes
|> Binary.createBuffer
|> CueReferenceFB.GetRootAsCueReferenceFB
@@ -164,7 +164,7 @@ type CueReference =
// ** FromYaml
- static member FromYaml(yaml: CueReferenceYaml) : Either =
+ static member FromYaml(yaml: CueReferenceYaml) : DiscoResult =
yaml.ToCueReference()
#endif
diff --git a/src/Disco/Disco/Core/Discovery.fs b/src/Disco/Disco/Core/Discovery.fs
index 14866e5a..cc85d9f5 100644
--- a/src/Disco/Disco/Core/Discovery.fs
+++ b/src/Disco/Disco/Core/Discovery.fs
@@ -61,12 +61,12 @@ type ServiceType =
try
str
|> ServiceType.Parse
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asParseError "ServiceType.TryParse"
- |> Either.fail
+ |> Result.fail
// ** ToOffset
@@ -83,26 +83,26 @@ type ServiceType =
static member FromFB(fb: ExposedServiceTypeFB) =
#if FABLE_COMPILER
match fb with
- | x when x = ExposedServiceTypeFB.GitFB -> Right Git
- | x when x = ExposedServiceTypeFB.RaftFB -> Right Raft
- | x when x = ExposedServiceTypeFB.HttpFB -> Right Http
- | x when x = ExposedServiceTypeFB.ApiFB -> Right Api
- | x when x = ExposedServiceTypeFB.WebSocketFB -> Right WebSocket
+ | x when x = ExposedServiceTypeFB.GitFB -> Ok Git
+ | x when x = ExposedServiceTypeFB.RaftFB -> Ok Raft
+ | x when x = ExposedServiceTypeFB.HttpFB -> Ok Http
+ | x when x = ExposedServiceTypeFB.ApiFB -> Ok Api
+ | x when x = ExposedServiceTypeFB.WebSocketFB -> Ok WebSocket
| x ->
sprintf "Unknown ExposedServiceTypeFB value: %d" x
|> Error.asParseError "ServiceType.FromFB"
- |> Either.fail
+ |> Result.fail
#else
match fb with
- | ExposedServiceTypeFB.GitFB -> Right Git
- | ExposedServiceTypeFB.RaftFB -> Right Raft
- | ExposedServiceTypeFB.HttpFB -> Right Http
- | ExposedServiceTypeFB.ApiFB -> Right Api
- | ExposedServiceTypeFB.WebSocketFB -> Right WebSocket
+ | ExposedServiceTypeFB.GitFB -> Ok Git
+ | ExposedServiceTypeFB.RaftFB -> Ok Raft
+ | ExposedServiceTypeFB.HttpFB -> Ok Http
+ | ExposedServiceTypeFB.ApiFB -> Ok Api
+ | ExposedServiceTypeFB.WebSocketFB -> Ok WebSocket
| x ->
sprintf "Unknown ExposedServiceTypeFB value: %O" x
|> Error.asParseError "ServiceType.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
@@ -148,7 +148,7 @@ type ExposedService =
// ** FromFB
static member FromFB (fb: ExposedServiceFB) =
- either {
+ result {
let! tipe = ServiceType.FromFB fb.Type
return { ServiceType = tipe; Port = port fb.Port }
}
@@ -341,20 +341,20 @@ type DiscoveredService =
// ** FromFB
static member FromFB(fb: DiscoveredServiceFB) =
- either {
+ result {
let! protocol =
match fb.Protocol with
- | "IPv4" -> Right IPProtocol.IPv4
- | "IPv6" -> Right IPProtocol.IPv6
+ | "IPv4" -> Ok IPProtocol.IPv4
+ | "IPv6" -> Ok IPProtocol.IPv6
| other ->
"Unknown protocol: " + other
|> Error.asParseError "Discovery.FromFB"
- |> Either.fail
+ |> Result.fail
let! metadata =
let arr = Array.zeroCreate fb.ExtraMetadataLength
Array.fold
- (fun (m: Either) _ -> either {
+ (fun (m: DiscoResult) _ -> result {
let! (idx, props) = m
#if FABLE_COMPILER
@@ -368,28 +368,28 @@ type DiscoveredService =
else
"Unable to parse empty Property value"
|> Error.asParseError "DiscoveredService.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
props.[idx] <- prop
return (idx + 1, props)
})
- (Right(0, arr))
+ (Ok(0, arr))
arr
- |> Either.map snd
+ |> Result.map snd
let! addressList =
let arr = Array.zeroCreate fb.AddressListLength
Array.fold
- (fun (m: Either) _ -> either {
+ (fun (m: DiscoResult) _ -> result {
let! (idx, addresses) = m
let! ip = fb.AddressList(idx) |> IpAddress.TryParse
addresses.[idx] <- ip
return (idx + 1, addresses)
})
- (Right(0, arr))
+ (Ok(0, arr))
arr
- |> Either.map snd
+ |> Result.map snd
let aliases =
[| for i = 0 to fb.AliasesLength - 1 do
@@ -407,13 +407,13 @@ type DiscoveredService =
else
"Unable to parse empty ServiceStatus"
|> Error.asParseError "DiscoveredService.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
let! services =
let arr = Array.zeroCreate fb.ServicesLength
Array.fold
- (fun (m: Either) _ -> either {
+ (fun (m: DiscoResult) _ -> result {
let! (idx, services) = m
#if FABLE_COMPILER
@@ -427,15 +427,15 @@ type DiscoveredService =
else
"Unable to parse empty ExposedService key/value"
|> Error.asParseError "DiscoveryService.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
services.[idx] <- service
return (idx + 1, services)
})
- (Right(0, arr))
+ (Ok(0, arr))
arr
- |> Either.map snd
+ |> Result.map snd
let! id = Id.decodeId fb
@@ -580,11 +580,11 @@ module Discovery =
#if FABLE_COMPILER
let prt = try Some(uint16 item.ValueString) with | _ -> None
match ServiceType.TryParse item.Key, prt with
- | Right st, (true, prt) -> Some { ServiceType = st; Port = port prt }
+ | Ok st, (true, prt) -> Some { ServiceType = st; Port = port prt }
| _ -> None
#else
match ServiceType.TryParse item.Key, UInt16.TryParse item.ValueString with
- | Right st, (true, prt) -> Some { ServiceType = st; Port = port prt }
+ | Ok st, (true, prt) -> Some { ServiceType = st; Port = port prt }
| _ -> None
#endif
@@ -607,22 +607,22 @@ module Discovery =
let private parseMachine (txt: ITxtRecord) =
match parseFieldWith (|Machine|_|) txt with
- | Some id -> id |> DiscoId.Parse |> Either.succeed
+ | Some id -> id |> DiscoId.Parse |> Result.succeed
| _ ->
"Could not find machine id in metatdata"
|> Error.asParseError (tag "parseMachine")
- |> Either.fail
+ |> Result.fail
// ** parseProtocol
let private parseProtocol (proto: AddressProtocol) =
match proto with
- | AddressProtocol.IPv4 -> Either.succeed IPv4
- | AddressProtocol.IPv6 -> Either.succeed IPv6
+ | AddressProtocol.IPv4 -> Result.succeed IPv4
+ | AddressProtocol.IPv6 -> Result.succeed IPv6
| x ->
"AddressProtocol could not be parsed: " + string x
|> Error.asParseError (tag "parseProtocol")
- |> Either.fail
+ |> Result.fail
// ** parseStatus
@@ -632,14 +632,14 @@ module Discovery =
let rawstatus = parseFieldWith (|Status|_|) record
match rawstatus, rawid, rawname with
- | Some MachineStatus.IDLE, _, _ -> Right Idle
+ | Some MachineStatus.IDLE, _, _ -> Ok Idle
| Some MachineStatus.BUSY, Some id, Some parsed
when not (isNull id) && not (isNull parsed) ->
- Busy (DiscoId.Parse id, name parsed) |> Either.succeed
+ Busy (DiscoId.Parse id, name parsed) |> Result.succeed
| _, _, _ ->
"Failed to parse Machine status: field(s) missing or null"
|> Error.asParseError (tag "parseStatus")
- |> Either.fail
+ |> Result.fail
// ** reservedField
@@ -701,7 +701,7 @@ module Discovery =
// ** toDiscoveredService
let toDiscoveredService (service: IResolvableService) =
- either {
+ result {
let entry = service.HostEntry
let! proto = parseProtocol service.AddressProtocol
diff --git a/src/Disco/Disco/Core/Either.fs b/src/Disco/Disco/Core/Either.fs
index 9463c940..96806040 100644
--- a/src/Disco/Disco/Core/Either.fs
+++ b/src/Disco/Disco/Core/Either.fs
@@ -9,74 +9,61 @@ namespace Disco.Core
open System
-// * Either Type
-
-// _____ _ _ _
-// | ____(_) |_| |__ ___ _ __
-// | _| | | __| '_ \ / _ \ '__|
-// | |___| | |_| | | | __/ |
-// |_____|_|\__|_| |_|\___|_|
-
-type Either<'err,'a> =
- | Right of 'a
- | Left of 'err
-
-// * Either Module
+// * Result Module
[]
-[]
-module Either =
+module Result =
// ** ofNullable
// FB types are not modeled with nullables in JS
#if FABLE_COMPILER
let ofNullable (v: 'T) (er: string -> 'Err) =
- Right v
+ Ok v
#else
let ofNullable (v: Nullable<'T>) (er: string -> 'Err) =
if v.HasValue
- then Right v.Value
- else "Item has no value" |> er |> Left
+ then Ok v.Value
+ else "Item has no value" |> er |> Error
#endif
// ** succeed
- /// ## lift a regular value into Either
+ /// ## lift a regular value into Result
///
/// ### Signature:
- /// - v: value to lift into Either
+ /// - v: value to lift into Result
///
- /// Returns: Either<^err, ^t>
- let succeed v = Right v
+ /// Returns: Result<^err, ^t>
+ let succeed v = Ok v
// ** fail
- /// ## lift an error value into Either
+ /// ## lift an error value into Result
///
/// ### Signature:
- /// - v: error to lift into Either
+ /// - v: error to lift into Result
///
- /// Returns: Either<^err, ^t>
- let fail v = Left v
+ /// Returns: Result<^err, ^t>
+ let fail v = Error v
// ** isFail
- /// ## Check if Either is a failure
+ /// ## Check if Result is a failure
///
- /// Check passed value of type Either<^err, ^t> for being a failure.
+ /// Check passed value of type Result<^err, ^t> for being a failure.
///
/// ### Signature:
/// - value: value to be checked
///
/// Returns: bool
let isFail = function
- | Left _ -> true
+ | Error _ -> true
| _ -> false
// ** isSuccess
- /// ## Check if Either value is a success
+ /// ## Check if Result value is a success
///
/// Check the passed value for being a success constructor.g
///
@@ -85,175 +72,116 @@ module Either =
///
/// Returns: bool
let isSuccess = function
- | Right _ -> true
+ | Ok _ -> true
| _ -> false
// ** get
- /// ## Extract success value from Either wrapper type
+ /// ## Extract success value from Result wrapper type
///
/// Extracts the result of a computation from the wrapper
- /// type. Crashes hard if the constructor is a Left (failure).
+ /// type. Crashes hard if the constructor is a Error (failure).
///
/// ### Signature:
- /// - value: Either<^err,^t> to extract result from
+ /// - value: Result<^err,^t> to extract result from
///
/// Returns: ^t
let get = function
- | Right result -> result
- | Left error ->
- failwithf "Either: cannot get result from failure: %A" error
+ | Ok result -> result
+ | Error error ->
+ failwithf "Result: cannot get result from failure: %A" error
// ** error
- /// ## Extract the embedded error value from an Either
+ /// ## Extract the embedded error value from an Result
///
- /// Extracts the embedded error value from the passed Either
+ /// Extracts the embedded error value from the passed Result
/// wrapper. Crashed hard if the constructor was actually a success.
///
/// ### Signature:
- /// - value: value of type Either<^err,^t> to extract error from
+ /// - value: value of type Result<^err,^t> to extract error from
///
/// Returns: ^err
let error = function
- | Left error -> error
- | Right _ ->
- failwith "Either: cannot get error from regular result"
+ | Error error -> error
+ | Ok _ ->
+ failwith "Result: cannot get error from regular result"
// ** iter
- let inline iter< ^a, ^err >(f: ^a -> unit) (a: Either< ^err, ^a >) =
+ let inline iter< ^a, ^err >(f: ^a -> unit) (a: Result< ^a,^err >) =
match a with
- | Right value -> f value
- | Left _ -> ()
+ | Ok value -> f value
+ | Error _ -> ()
// ** iterError
- let inline iterError< ^a, ^err >(f: ^err -> unit) (a: Either< ^err, ^a >) =
- match a with
- | Left error -> f error
- | Right _ -> ()
-
- // ** unwrap
-
- /// Gets the value if it's successful and runs the provided function otherwise
- let inline unwrap< ^a, ^err > (fail: ^err -> ^a) (a: Either< ^err, ^a >) =
- match a with
- | Right value -> value
- | Left err -> fail err
-
- // ** bind
-
- /// ## Bind a function to the result of a computation
- ///
- /// Inspects the passed value `a` and applies the function `f` to
- /// the embedded value, *if* `a` was a `Right` (or success). Errors
- /// are just passed through.
- ///
- /// ### Signature:
- /// - `f`: function to apply to the embedded value of `a`
- /// - `a`: value of type Either<^err, ^t> to apply `f` to
- ///
- /// Returns: Either<^err, ^t>
- let inline bind< ^a, ^b, ^err >
- (f: ^a -> Either< ^err, ^b >)
- (a: Either< ^err, ^a >)
- : Either< ^err, ^b > =
+ let inline iterError< ^a, ^err >(f: ^err -> unit) (a: Result< ^a, ^err >) =
match a with
- | Right value -> f value
- | Left err -> Left err
-
- // ** map
+ | Error error -> f error
+ | Ok _ -> ()
- /// ## Map over an embedded value
- ///
- /// Applies a function `f` to the inner value of `a`, *if* `a`
- /// indeed is a `Right`.
- ///
- /// ### Signature:
- /// - `f`: function to apply to the inner value of `a`
- /// - `a`: value to extract and apply `f` to
- ///
- /// Returns: Either<^err, ^t>
- let inline map< ^a, ^b, ^err >
- (f: ^a -> ^b)
- (a: Either< ^err, ^a >)
- : Either< ^err, ^b > =
- match a with
- | Right value -> f value |> succeed
- | Left error -> Left error
+ // ** bindArray
- let bindArray(f: 'a -> Either<'err,'b>) (arr:'a[]): Either<'err,'b[]> =
+ let bindArray(f: 'a -> Result<'b,'err>) (arr:'a[]): Result<'b[],'err> =
let mutable i = 0
let mutable error = None
let arr2 = Array.zeroCreate arr.Length
while i < arr.Length && Option.isNone error do
match f arr.[i] with
- | Right value -> arr2.[i] <- value; i <- i + 1
- | Left err -> error <- Some err
+ | Ok value -> arr2.[i] <- value; i <- i + 1
+ | Error err -> error <- Some err
match error with
- | Some err -> Left err
- | None -> Right arr2
+ | Some err -> Error err
+ | None -> Ok arr2
- // ** mapError
+ // ** unwrap
- /// ## Map over the embedded error value
- ///
- /// Inspects the passed value `a` and applies the function `f`, *if*
- /// `a` is a `Left`.
- ///
- /// ### Signature:
- /// - `f`: function to apply to the inner error value
- /// - `a`: value of type Either<^err,^t>
- ///
- /// Returns: Either<^err, ^t>
- let inline mapError< ^a, ^err1, ^err2 >
- (f: ^err1 -> ^err2)
- (a: Either< ^err1, ^a >)
- : Either< ^err2, ^a> =
+ /// Gets the value if it's successful and runs the provided function otherwise
+ let inline unwrap< ^a, ^err > (fail: ^err -> ^a) (a: Result< ^a,^err >) =
match a with
- | Right value -> Right value
- | Left error -> Left(f error)
+ | Ok value -> value
+ | Error err -> fail err
// ** combine
let inline combine< ^a, ^b, ^err >
(v1 : ^a)
- (v2 : Either< ^err, ^b >)
- : Either< ^err, (^a * ^b) > =
+ (v2 : Result< ^b,^err >)
+ : Result< (^a * ^b),^err > =
match v2 with
- | Right value2 -> succeed (v1, value2)
- | Left err -> Left err
+ | Ok value2 -> succeed (v1, value2)
+ | Error err -> Error err
// ** ofOption
- /// ## Transform an Option value into an Either
+ /// ## Transform an Option value into a Result
///
/// Converts the passed value of type `'t option` into an
- /// Either<^err, ^t>. If the passed value is a `None`, use the
- /// provided error value in the `Left`.
+ /// Result<^t,^err>. If the passed value is a `None`, use the
+ /// provided error value in the `Error`.
///
/// ### Signature:
/// - err: error value to use when `a` is `None`
/// - `a`: value to convert
///
- /// Returns: Either<^err,^t>
+ /// Returns: Result<^t,^err>
let inline ofOption< ^a, ^b, ^err >
(err: ^err)
(a: ^a option)
- : Either< ^err, ^a > =
+ : Result< ^a,^err > =
match a with
- | Some value -> Right value
- | None -> Left err
+ | Some value -> Ok value
+ | None -> Error err
// ** nothing
- let inline nothing< ^err > : Either< ^err,unit > =
+ let inline nothing< ^err > : Result =
succeed ()
// ** ignore
- let inline ignore< ^err > _ : Either< ^err, unit > =
+ let inline ignore< ^err > _ : Result =
succeed ()
// ** tryWith
@@ -261,7 +189,7 @@ module Either =
let inline tryWith< ^a, ^err >
(err: (string -> ^err))
(f: unit -> ^a)
- : Either< ^err, ^a > =
+ : Result< ^a, ^err > =
try
f() |> succeed
with
@@ -274,56 +202,48 @@ module Either =
// ** orElse
let inline orElse value = function
- | Right _ as good -> good
- | Left _ -> Right value
+ | Ok _ as good -> good
+ | Error _ -> Ok value
// ** defaultValue
let defaultValue def = function
- | Right value -> value
- | Left _ -> def
-
-// * Either Builder
+ | Ok value -> value
+ | Error _ -> def
-// _____ _ _ _ ____ _ _ _
-// | ____(_) |_| |__ ___ _ __ | __ ) _ _(_) | __| | ___ _ __
-// | _| | | __| '_ \ / _ \ '__| | _ \| | | | | |/ _` |/ _ \ '__|
-// | |___| | |_| | | | __/ | | |_) | |_| | | | (_| | __/ |
-// |_____|_|\__|_| |_|\___|_| |____/ \__,_|_|_|\__,_|\___|_|
+// * Result Builder
[]
-module EitherUtils =
+module ResultUtils =
- type EitherBuilder() =
+ type ResultBuilder() =
- member self.Return(v: 'a): Either<'err, 'a> = Right v
+ member self.Return(v: 'a): Result<'a,'err> = Ok v
- member self.ReturnFrom(v: Either<'err, 'a>): Either<'err, 'a> = v
+ member self.ReturnFrom(v: Result<'a,'err>): Result<'a,'err> = v
- member self.Bind(m: Either<'err, 'a>, f: 'a -> Either<'err, 'b>): Either<'err, 'b> =
- match m with
- | Right value -> f value
- | Left err -> Left err
+ member self.Bind(m: Result<'a,'err>, f: 'a -> Result<'b,'err>): Result<'b,'err> =
+ Result.bind f m
- member self.Zero(): Either<'err, unit> = Right ()
+ member self.Zero(): Result = Ok ()
- member self.Delay(f: unit -> Either<'err, 'a>) = f
+ member self.Delay(f: unit -> Result<'a,'err>) = f
- member self.Run(f: unit -> Either<'err, 'a>) = f()
+ member self.Run(f: unit -> Result<'a,'err>) = f()
- member self.While(guard: unit -> bool, body: unit -> Either<'err, unit>): Either<'err, unit> =
+ member self.While(guard: unit -> bool, body: unit -> Result): Result =
if guard ()
then self.Bind(body(), fun () -> self.While(guard, body))
else self.Zero()
- member self.For(sequence:seq<'a>, body: 'a -> Either<'err, unit>): Either<'err, unit> =
+ member self.For(sequence:seq<'a>, body: 'a -> Result): Result =
self.Using(sequence.GetEnumerator(), fun enum ->
self.While(enum.MoveNext, fun () -> body enum.Current))
member self.Combine(a, b) =
match a with
- | Right _ -> a
- | Left _ -> b
+ | Ok _ -> a
+ | Error _ -> b
member self.TryWith(body, handler) =
try body() |> self.ReturnFrom
@@ -336,17 +256,17 @@ module EitherUtils =
handler ()
member self.Using<'a, 'b, 'err when 'a :> IDisposable>
- (disposable: 'a, body: 'a -> Either<'err, 'b>): Either<'err, 'b> =
+ (disposable: 'a, body: 'a -> Result<'b,'err>): Result<'b,'err> =
let body' = fun () -> body disposable
self.TryFinally(body', fun () ->
disposable.Dispose())
- let either = EitherBuilder()
+ let result = ResultBuilder()
#if INTERACTIVE
module Test =
- open EitherUtils
+ open ResultUtils
type DisposableAction(f) =
interface IDisposable with
@@ -360,15 +280,15 @@ module Test =
let orFail x =
match x with
- | Left err -> printfn "ERROR: %O" err
- | Right v -> printfn "OK: %O" v
+ | Error err -> printfn "ERROR: %O" err
+ | Ok v -> printfn "OK: %O" v
let riskyOp x =
printfn "Evaluating %O..." x
- if x = 0 then Left "boom!" else Right ()
+ if x = 0 then Error "boom!" else Ok ()
let test() =
- let test = either {
+ let test = result {
printfn "This should be lazy but it's evaluated eagerly"
let ar = [|1;2;0;3|]
let mutable i = 0
@@ -381,13 +301,13 @@ module Test =
orFail test
// No problem here
- either {
+ result {
for x in [1;2;3] do
do! riskyOp x
} |> orFail
// Boom!
- either {
+ result {
for x in [|1;2;0;3|] do
do! riskyOp x
} |> orFail
@@ -396,10 +316,10 @@ module Test =
let isDisposed = ref false
let step1ok = ref false
let step2ok = ref false
- let resource = either {
+ let resource = result {
return new DisposableAction(fun () -> isDisposed := true)
}
- either {
+ result {
use! r = resource
step1ok := not !isDisposed
} |> ignore
@@ -434,4 +354,4 @@ module OptionUtils =
member __.Run (f) = f()
- let maybe = new MaybeBuilder()
+ let maybe = MaybeBuilder()
diff --git a/src/Disco/Disco/Core/Error.fs b/src/Disco/Disco/Core/Error.fs
index d39025d5..1c59decd 100644
--- a/src/Disco/Disco/Core/Error.fs
+++ b/src/Disco/Disco/Core/Error.fs
@@ -87,35 +87,35 @@ type DiscoError =
static member FromFB (fb: ErrorFB) =
match fb.Type with
#if FABLE_COMPILER
- | x when x = ErrorTypeFB.OKFB -> Right OK
- | x when x = ErrorTypeFB.OtherFB -> Right (Other (fb.Location,fb.Message))
- | x when x = ErrorTypeFB.GitErrorFB -> Right (GitError (fb.Location,fb.Message))
- | x when x = ErrorTypeFB.ProjectErrorFB -> Right (ProjectError (fb.Location,fb.Message))
- | x when x = ErrorTypeFB.AssetErrorFB -> Right (AssetError (fb.Location,fb.Message))
- | x when x = ErrorTypeFB.RaftErrorFB -> Right (RaftError (fb.Location,fb.Message))
- | x when x = ErrorTypeFB.ParseErrorFB -> Right (ParseError (fb.Location,fb.Message))
- | x when x = ErrorTypeFB.SocketErrorFB -> Right (SocketError (fb.Location,fb.Message))
- | x when x = ErrorTypeFB.ClientErrorFB -> Right (ClientError (fb.Location,fb.Message))
- | x when x = ErrorTypeFB.IOErrorFB -> Right (IOError (fb.Location,fb.Message))
+ | x when x = ErrorTypeFB.OKFB -> Ok OK
+ | x when x = ErrorTypeFB.OtherFB -> Ok (Other (fb.Location,fb.Message))
+ | x when x = ErrorTypeFB.GitErrorFB -> Ok (GitError (fb.Location,fb.Message))
+ | x when x = ErrorTypeFB.ProjectErrorFB -> Ok (ProjectError (fb.Location,fb.Message))
+ | x when x = ErrorTypeFB.AssetErrorFB -> Ok (AssetError (fb.Location,fb.Message))
+ | x when x = ErrorTypeFB.RaftErrorFB -> Ok (RaftError (fb.Location,fb.Message))
+ | x when x = ErrorTypeFB.ParseErrorFB -> Ok (ParseError (fb.Location,fb.Message))
+ | x when x = ErrorTypeFB.SocketErrorFB -> Ok (SocketError (fb.Location,fb.Message))
+ | x when x = ErrorTypeFB.ClientErrorFB -> Ok (ClientError (fb.Location,fb.Message))
+ | x when x = ErrorTypeFB.IOErrorFB -> Ok (IOError (fb.Location,fb.Message))
| x ->
("DiscoError.FromFB", sprintf "Could not parse unknown ErrorTypeFB: %A" x)
|> ParseError
- |> Either.fail
+ |> Result.fail
#else
- | ErrorTypeFB.OKFB -> Right OK
- | ErrorTypeFB.OtherFB -> Right (Other (fb.Location,fb.Message))
- | ErrorTypeFB.GitErrorFB -> Right (GitError (fb.Location,fb.Message))
- | ErrorTypeFB.ProjectErrorFB -> Right (ProjectError (fb.Location,fb.Message))
- | ErrorTypeFB.AssetErrorFB -> Right (AssetError (fb.Location,fb.Message))
- | ErrorTypeFB.RaftErrorFB -> Right (RaftError (fb.Location,fb.Message))
- | ErrorTypeFB.ParseErrorFB -> Right (ParseError (fb.Location,fb.Message))
- | ErrorTypeFB.SocketErrorFB -> Right (SocketError (fb.Location,fb.Message))
- | ErrorTypeFB.ClientErrorFB -> Right (ClientError (fb.Location,fb.Message))
- | ErrorTypeFB.IOErrorFB -> Right (IOError (fb.Location,fb.Message))
+ | ErrorTypeFB.OKFB -> Ok OK
+ | ErrorTypeFB.OtherFB -> Ok (Other (fb.Location,fb.Message))
+ | ErrorTypeFB.GitErrorFB -> Ok (GitError (fb.Location,fb.Message))
+ | ErrorTypeFB.ProjectErrorFB -> Ok (ProjectError (fb.Location,fb.Message))
+ | ErrorTypeFB.AssetErrorFB -> Ok (AssetError (fb.Location,fb.Message))
+ | ErrorTypeFB.RaftErrorFB -> Ok (RaftError (fb.Location,fb.Message))
+ | ErrorTypeFB.ParseErrorFB -> Ok (ParseError (fb.Location,fb.Message))
+ | ErrorTypeFB.SocketErrorFB -> Ok (SocketError (fb.Location,fb.Message))
+ | ErrorTypeFB.ClientErrorFB -> Ok (ClientError (fb.Location,fb.Message))
+ | ErrorTypeFB.IOErrorFB -> Ok (IOError (fb.Location,fb.Message))
| x ->
("DiscoError.FromFB", sprintf "Could not parse unknown ErrotTypeFB: %A" x)
|> ParseError
- |> Either.fail
+ |> Result.fail
#endif
// ** ToOffset
@@ -167,6 +167,10 @@ type DiscoError =
+// * DiscoResult
+
+type DiscoResult<'t> = Result<'t,DiscoError>
+
// * Error Module
[]
module Error =
@@ -267,10 +271,10 @@ module Error =
/// - `a`: value to apply function
///
/// Returns: ^b
- let inline orExit (f: ^a -> ^b) (a: Either< DiscoError, ^a>) : ^b =
+ let inline orExit (f: ^a -> ^b) (a: DiscoResult< ^a >) : ^b =
match a with
- | Right value -> f value
- | Left error -> exitWith error
+ | Ok value -> f value
+ | Error error -> exitWith error
let asGitError loc err = GitError(loc,err)
let asProjectError loc err = ProjectError(loc,err)
diff --git a/src/Disco/Disco/Core/FileSystem.fs b/src/Disco/Disco/Core/FileSystem.fs
index 81a54e34..d1f9fbf3 100644
--- a/src/Disco/Disco/Core/FileSystem.fs
+++ b/src/Disco/Disco/Core/FileSystem.fs
@@ -94,20 +94,20 @@ type FsPath =
// ** FromFB
static member FromFB(fb: FsPathFB) =
- either {
+ result {
let! platform = Platform.FromFB fb.Platform
let drive = Convert.ToChar fb.Drive
let! elements =
if fb.ElementsLength > 0 then
Array.fold
- (fun (lst:Either) idx -> either {
+ (fun (lst:DiscoResult) idx -> result {
let! elms = lst
let elm = fb.Elements idx
return elm :: elms
})
- (Right List.empty)
+ (Ok List.empty)
[| 0 .. fb.ElementsLength - 1 |]
- else Either.succeed List.empty
+ else Result.succeed List.empty
return {
Drive = drive
Platform = platform
@@ -121,7 +121,7 @@ type FsPath =
// ** FromBytes
- static member FromBytes (bytes: byte array) : Either =
+ static member FromBytes (bytes: byte array) : DiscoResult =
bytes
|> Binary.createBuffer
|> FsPathFB.GetRootAsFsPathFB
@@ -240,7 +240,7 @@ type FsEntry =
// ** FromEntryFB
static member FromEntryFB(fb: FsInfoFB) =
- either {
+ result {
let! path =
#if FABLE_COMPILER
FsPath.FromFB fb.Path
@@ -252,7 +252,7 @@ type FsEntry =
else
"Cannot parse empty path value"
|> Error.asParseError "FsTree.toEntry"
- |> Either.fail
+ |> Result.fail
#endif
let info =
{ Path = path
@@ -278,7 +278,7 @@ type FsEntry =
other
|> sprintf "%A is not a known FsEntry type"
|> Error.asParseError "FsTree.toEntry"
- |> Either.fail
+ |> Result.fail
}
// ** ToOffset
@@ -307,7 +307,7 @@ type FsEntry =
// ** FromFB
static member FromFB(fb:FsEntryFB) =
- either {
+ result {
let! root =
#if FABLE_COMPILER
FsEntry.FromEntryFB fb.Root
@@ -319,7 +319,7 @@ type FsEntry =
else
"Could not parse empty FsEntry root value"
|> Error.asParseError "FsEntry.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
match root with
@@ -328,7 +328,7 @@ type FsEntry =
| FsEntry.Directory _ ->
return!
List.fold
- (fun (m:Either) idx -> either {
+ (fun (m:DiscoResult) idx -> result {
let! lst = m
let! child =
#if FABLE_COMPILER
@@ -343,18 +343,18 @@ type FsEntry =
else
"Could not parse empty child value"
|> Error.asParseError "FsEntry.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
return child :: lst
})
- (Right List.empty)
+ (Ok List.empty)
[ 0 .. fb.ChildrenLength - 1 ]
- |> Either.map (List.rev >> FsEntry.inflate root)
+ |> Result.map (List.rev >> FsEntry.inflate root)
}
// ** FromBytes
- static member FromBytes (bytes: byte array) : Either =
+ static member FromBytes (bytes: byte array) : DiscoResult =
bytes
|> Binary.createBuffer
|> FsEntryFB.GetRootAsFsEntryFB
@@ -433,7 +433,7 @@ type FsTree =
// ** FromBytes
- static member FromBytes (bytes: byte array) : Either =
+ static member FromBytes (bytes: byte array) : DiscoResult =
bytes
|> Binary.createBuffer
|> FsTreeFB.GetRootAsFsTreeFB
@@ -446,7 +446,7 @@ type FsTree =
// ** FromFB
static member FromFB(fb:FsTreeFB) =
- either {
+ result {
let! hostId = Id.decodeHostId fb
let filters =
fb.Filters.Split(' ')
@@ -462,11 +462,11 @@ type FsTree =
else
"Could not parse empty root"
|> Error.asParseError "FsTree.FromtFB"
- |> Either.fail
+ |> Result.fail
#endif
let! children =
Array.fold
- (fun (m:Either) idx -> either {
+ (fun (m:DiscoResult) idx -> result {
let! list = m
let! child =
#if FABLE_COMPILER
@@ -481,11 +481,11 @@ type FsTree =
else
"Could not parse empty child"
|> Error.asParseError "FsTree.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
return child :: list
})
- (Right List.empty)
+ (Ok List.empty)
[| 0 .. fb.ChildrenLength - 1 |]
return
children
@@ -744,11 +744,11 @@ module File =
path
|> unwrap
|> File.Delete
- |> Either.succeed
+ |> Result.succeed
with exn ->
exn.Message
|> Error.asIOError (tag "delete")
- |> Either.fail
+ |> Result.fail
// ** ensurePath
@@ -757,11 +757,11 @@ module File =
path
|> Path.getDirectoryName
|> Directory.createDirectory
- |> Either.ignore
+ |> Result.ignore
with exn ->
exn.Message
|> Error.asIOError (tag "ensurePath")
- |> Either.fail
+ |> Result.fail
#endif
@@ -782,18 +782,18 @@ module Directory =
/// Create a new directory. Upon failure, return an DiscoError
///
/// FilePath
- /// Either
+ /// DiscoResult
let createDirectory (path: FilePath) =
try
path
|> unwrap
|> Directory.CreateDirectory
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asIOError (tag "createDirectory")
- |> Either.fail
+ |> Result.fail
// ** removeDirectory
@@ -801,11 +801,11 @@ module Directory =
try
unwrap path
|> Directory.Delete
- |> Either.succeed
+ |> Result.succeed
with | exn ->
exn.Message
|> Error.asIOError (tag "removeDirectory")
- |> Either.fail
+ |> Result.fail
// ** info
@@ -921,8 +921,8 @@ module FileSystem =
/// ### Signature:
/// - path: FilePath to delete
///
- /// Returns: Either
- let rec rmDir (path: FilePath) : Either =
+ /// Returns: DiscoResult
+ let rec rmDir (path: FilePath) : DiscoResult =
try
let info = new FileInfo(unwrap path)
info.IsReadOnly <- false
@@ -930,28 +930,28 @@ module FileSystem =
if (attrs &&& FileAttributes.Directory) = FileAttributes.Directory then
let children = DirectoryInfo(unwrap path).EnumerateFileSystemInfos()
if children.Count() > 0 then
- either {
+ result {
do! Seq.fold
- (fun (_: Either) (child: FileSystemInfo) -> either {
+ (fun (_: DiscoResult) (child: FileSystemInfo) -> result {
return! child.FullName |> filepath |> rmDir
})
- (Right ())
+ (Ok ())
children
return Directory.Delete(unwrap path)
}
else
Directory.Delete(unwrap path)
- |> Either.succeed
+ |> Result.succeed
else
path
|> unwrap
|> File.Delete
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
("FileSystem.rmDir", exn.Message)
|> IOError
- |> Either.fail
+ |> Result.fail
#endif
@@ -995,7 +995,7 @@ module FileSystem =
/// ### Signature:
/// - path: FilePath
///
- /// Returns: Either
+ /// Returns: DiscoResult
let mkDir (path: FilePath) =
try
if path |> unwrap |> Directory.Exists |> not then
@@ -1003,14 +1003,14 @@ module FileSystem =
|> unwrap
|> Directory.CreateDirectory
|> ignore
- |> Either.succeed
+ |> Result.succeed
else
- Either.succeed ()
+ Result.succeed ()
with
| exn ->
("FileSystem.mkDir", exn.Message)
|> IOError
- |> Either.fail
+ |> Result.fail
#endif
@@ -1026,9 +1026,9 @@ module FileSystem =
/// - source: FilePath
/// - target: FilePath
///
- /// Returns: Either
+ /// Returns: DiscoResult
- let rec copyDir (source: FilePath) (target: FilePath) : Either =
+ let rec copyDir (source: FilePath) (target: FilePath) : DiscoResult =
try
let source = Directory.info source
@@ -1046,12 +1046,12 @@ module FileSystem =
let destpath = filepath target.FullName > filepath dir.Name
copyDir (filepath dir.FullName) destpath |> ignore
- Either.succeed ()
+ Result.succeed ()
with
| exn ->
("FileSystem.mkDir", exn.Message)
|> IOError
- |> Either.fail
+ |> Result.fail
#endif
@@ -1509,13 +1509,13 @@ module FsTree =
basePath
|> sprintf "%A was not found or is not a directory"
|> Error.asAssetError "FsTree"
- |> Either.fail
- either {
+ |> Result.fail
+ result {
let! root =
if Directory.exists basePath then
let path = FsPath.parse basePath
match FsEntry.create path with
- | Some root -> Right root
+ | Some root -> Ok root
| None -> notFound()
else notFound()
return {
@@ -1680,11 +1680,11 @@ module FsTree =
|> List.choose id
|> inflate host root
|> setFilters filters
- |> Either.succeed
+ |> Result.succeed
| None ->
"Could not parse root entry: does the directory exist?"
|> Error.asIOError "FsTree.read"
- |> Either.fail
+ |> Result.fail
#endif
@@ -1739,7 +1739,7 @@ module FsTreeTesting =
fp
|> File.readBytes
|> Binary.decode
- |> Either.get
+ |> Result.get
let roundTrip dirCount fileCount =
let fp = Path.getTempFile()
diff --git a/src/Disco/Disco/Core/Git.fs b/src/Disco/Disco/Core/Git.fs
index 6a9113c4..eee2f353 100644
--- a/src/Disco/Disco/Core/Git.fs
+++ b/src/Disco/Disco/Core/Git.fs
@@ -80,12 +80,12 @@ module Git =
url
|> Repository.ListRemoteReferences
|> Seq.cast
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "lsRemote")
- |> Either.fail
+ |> Result.fail
// ** Branch module
@@ -119,12 +119,12 @@ module Git =
let create (name: string) (repo: Repository) =
try
repo.CreateBranch(name)
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "create")
- |> Either.fail
+ |> Result.fail
// *** current
@@ -147,14 +147,14 @@ module Git =
/// ### Signature:
/// - branch: Branch
///
- /// Returns: Either
- let tracked (branch: Branch) : Either =
+ /// Returns: Result
+ let tracked (branch: Branch) : DiscoResult =
match branch.TrackedBranch with
| null ->
"No tracked branch"
|> Error.asGitError (tag "tracked")
- |> Either.fail
- | branch -> Either.succeed branch
+ |> Result.fail
+ | branch -> Result.succeed branch
// *** tracking
@@ -166,13 +166,13 @@ module Git =
/// - branch: Branch to get details for
///
/// Returns: BranchTrackingDetails option
- let tracking (branch: Branch) : Either =
+ let tracking (branch: Branch) : DiscoResult =
match branch.TrackingDetails with
| null ->
"No tracked branch"
|> Error.asGitError (tag "tracking")
- |> Either.fail
- | details -> Either.succeed details
+ |> Result.fail
+ | details -> Result.succeed details
// *** tip
@@ -310,7 +310,7 @@ module Git =
/// - remote: string
/// - upstream: string
///
- /// Returns: Either
+ /// Returns: DiscoResult
let setTracked (repo: Repository) (branch: Branch) (remote: Remote) =
try
@@ -318,12 +318,12 @@ module Git =
updater.Remote <- remote.Name
updater.UpstreamBranch <- branch.CanonicalName
repo.Branches.Update (branch, setRemote)
- |> Either.ignore
+ |> Result.ignore
with
| exn ->
exn.Message
|> Error.asGitError (tag "setTracked")
- |> Either.fail
+ |> Result.fail
// ** Repo
@@ -396,12 +396,12 @@ module Git =
let setReceivePackConfig (repo: Repository) =
try
repo.Config.Set("receive.denyCurrentBranch", "updateInstead")
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "setReceivePackConfig")
- |> Either.fail
+ |> Result.fail
#endif
@@ -415,10 +415,10 @@ module Git =
/// - target: FilePath to target directory
/// - remote: string specifiying the remote repository address
///
- /// Returns: Either
+ /// Returns: DiscoResult
let clone (target: FilePath) (remote: string) =
try
- either {
+ result {
let path = Repository.Clone(remote, unwrap target)
let repo = new Repository(path)
do! setReceivePackConfig repo
@@ -427,7 +427,7 @@ module Git =
| exn ->
exn.Message
|> Error.asGitError (tag "clone")
- |> Either.fail
+ |> Result.fail
// *** branches
@@ -484,12 +484,12 @@ module Git =
let reset (opts: ResetMode) (repo: Repository) =
try
repo.Reset opts
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "reset")
- |> Either.fail
+ |> Result.fail
// *** resetTo
@@ -506,12 +506,12 @@ module Git =
let resetTo (opts: ResetMode) (commit: Commit) (repo: Repository) =
try
repo.Reset(opts, commit)
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "resetTo")
- |> Either.fail
+ |> Result.fail
// *** clean
@@ -628,8 +628,8 @@ module Git =
spec
|> String.format "{0} not found"
|> Error.asGitError (tag "checkout")
- |> Either.fail
- | branch -> Either.succeed branch
+ |> Result.fail
+ | branch -> Result.succeed branch
// *** repository
@@ -641,7 +641,7 @@ module Git =
/// - path: FilePath to search for the .git folder
///
/// Returns: Repository option
- let repository (path: FilePath) : Either =
+ let repository (path: FilePath) : DiscoResult =
try
let normalized =
if Path.endsWith ".git" path then
@@ -650,17 +650,17 @@ module Git =
path > filepath ".git"
new Repository(unwrap normalized)
- |> Either.succeed
+ |> Result.succeed
with
| :? RepositoryNotFoundException as exn ->
exn.Message
|> String.format (unwrap path + ": {0}")
|> Error.asGitError (tag "repository")
- |> Either.fail
+ |> Result.fail
| exn ->
exn.Message
|> Error.asGitError (tag "repository")
- |> Either.fail
+ |> Result.fail
// *** init
@@ -671,7 +671,7 @@ module Git =
/// ### Signature:
/// - path: FilePath pointing to the target directory
///
- /// Returns: Either,Repository>
+ /// Returns: DiscoResult
let init (path: FilePath) =
try
Path.map Repository.Init path |> ignore
@@ -680,7 +680,7 @@ module Git =
| exn ->
exn.Message
|> Error.asGitError (tag "init")
- |> Either.fail
+ |> Result.fail
// *** add
@@ -690,18 +690,18 @@ module Git =
path
|> String.format "Path must be relative to the project root: {0}"
|> Error.asGitError (tag "add")
- |> Either.fail
+ |> Result.fail
else
if File.exists path || Directory.exists path then
runGit repo.Info.WorkingDirectory "add" "." ""
- |> Either.ignore
+ |> Result.ignore
else
- Either.succeed ()
+ Result.succeed ()
with
| exn ->
exn.Message
|> Error.asGitError (tag "add")
- |> Either.fail
+ |> Result.fail
// *** stage
@@ -709,17 +709,17 @@ module Git =
try
if Path.isPathRooted path && not (repo.Ignore.IsPathIgnored (unwrap path))then
runGit repo.Info.WorkingDirectory "stage" "." ""
- |> Either.ignore
+ |> Result.ignore
else
path
|> String.format "Paths must be absolute: {0}"
|> Error.asGitError (tag "stage")
- |> Either.fail
+ |> Result.fail
with
| exn ->
exn.Message
|> Error.asGitError (tag "stage")
- |> Either.fail
+ |> Result.fail
// *** stageAll
@@ -731,24 +731,24 @@ module Git =
try
repo.RetrieveStatus()
|> Seq.iter _stage
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "stageAll")
- |> Either.fail
+ |> Result.fail
// *** commit
let commit (repo: Repository) (msg: string) (committer: Signature) =
try
repo.Commit(msg, committer, committer)
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "commit")
- |> Either.fail
+ |> Result.fail
// *** status
@@ -760,15 +760,15 @@ module Git =
/// - repo: Repository to fetch status for
///
/// Returns: RepositoryStatus
- let status (repo: Repository) : Either =
+ let status (repo: Repository) : DiscoResult =
try
repo.RetrieveStatus()
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "status")
- |> Either.fail
+ |> Result.fail
// *** isDirty
@@ -780,8 +780,8 @@ module Git =
/// - repo: Repository to check
///
/// Returns: boolean
- let isDirty (repo: Repository) : Either =
- either {
+ let isDirty (repo: Repository) : DiscoResult =
+ result {
let! status = status repo
return status.IsDirty
}
@@ -796,8 +796,8 @@ module Git =
/// - repo: Repository
///
/// Returns: seq
- let untracked (repo: Repository) : Either> =
- either {
+ let untracked (repo: Repository) : DiscoResult> =
+ result {
let! status = status repo
return status.Untracked
}
@@ -827,15 +827,15 @@ module Git =
/// - t: IQueryableCommitLog
///
/// Returns: Commit
- let elementAt (idx: int) (t: IQueryableCommitLog) : Either =
+ let elementAt (idx: int) (t: IQueryableCommitLog) : DiscoResult =
try
t.ElementAt(idx)
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "elementAt")
- |> Either.fail
+ |> Result.fail
// *** commitCount
@@ -859,12 +859,12 @@ module Git =
let basepath = Path.GetDirectoryName repo.Info.Path
branch.FriendlyName
|> runGit basepath "push" remote.Name
- |> Either.ignore
+ |> Result.ignore
with
| exn ->
exn.Message
|> Error.asGitError (tag "push")
- |> Either.fail
+ |> Result.fail
// *** pull
@@ -876,11 +876,11 @@ module Git =
/// - repo: Repository
/// - remote: string
///
- /// Returns: Either
+ /// Returns: DiscoResult
let pull (repo: Repository) (signature: Signature) =
try
- either {
+ result {
let options =
let fopts = FetchOptions()
let popts = PullOptions()
@@ -896,7 +896,7 @@ module Git =
| exn ->
exn.Message
|> Error.asGitError (tag "pull")
- |> Either.fail
+ |> Result.fail
// *** lsRemote
@@ -905,12 +905,12 @@ module Git =
remote
|> repo.Network.ListReferences
|> Seq.cast
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "lsRemote")
- |> Either.fail
+ |> Result.fail
// ** Config
@@ -946,12 +946,12 @@ module Git =
let addRemote (repo: Repository) (name: string) (url: Url) =
try
repo.Network.Remotes.Add(name, unwrap url)
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "addRemote")
- |> Either.fail
+ |> Result.fail
// *** updateRemote
@@ -961,18 +961,18 @@ module Git =
updater.Url <- unwrap url
repo.Network.Remotes.Update(remote.Name, update)
repo.Network.Remotes.[remote.Name]
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asGitError (tag "updateRemote")
- |> Either.fail
+ |> Result.fail
// *** delRemote
- let delRemote (repo: Repository) (name: string) : Either =
+ let delRemote (repo: Repository) (name: string) : DiscoResult =
repo.Network.Remotes.Remove name
- |> Either.succeed
+ |> Result.succeed
#endif
@@ -1031,6 +1031,6 @@ repo.Network.Fetch("git@bitbucket.org:krgn/meh.git", ["master"], "hello")
Commands.Pull(repo, User.Admin.Signature, options)
-repo.Network.Push(fix_issue |> Either.get)
+repo.Network.Push(fix_issue |> Result.get)
#endif
diff --git a/src/Disco/Disco/Core/Id.fs b/src/Disco/Disco/Core/Id.fs
index ad4908ff..278160c9 100644
--- a/src/Disco/Disco/Core/Id.fs
+++ b/src/Disco/Disco/Core/Id.fs
@@ -56,11 +56,11 @@ type DiscoId =
// ** TryParse
static member TryParse (str: string) =
- try DiscoId.Parse str |> Either.succeed
+ try DiscoId.Parse str |> Result.succeed
with exn ->
exn.Message
|> Error.asParseError "DiscoId"
- |> Either.fail
+ |> Result.fail
// ** FromGuid
@@ -127,7 +127,7 @@ module Id =
[| 0 .. 15 |]
|> Array.map t
|> DiscoId.FromByteArray
- |> Either.succeed
+ |> Result.succeed
let inline decodeId (fb: ^t) =
(fun idx -> (^t : (member Id: int -> byte) fb, idx))
diff --git a/src/Disco/Disco/Core/Interfaces.fs b/src/Disco/Disco/Core/Interfaces.fs
index d02ddb80..3532555d 100644
--- a/src/Disco/Disco/Core/Interfaces.fs
+++ b/src/Disco/Disco/Core/Interfaces.fs
@@ -103,7 +103,6 @@ type DiscoEvent =
| EnterJointConsensus of changes:ConfigChange array
| LeaderChanged of leader:MemberId option
| StateChanged of oldstate:MemberState * newstate:MemberState
- | PersistSnapshot of log:RaftLogEntry
| RaftError of error:DiscoError
| Status of ServiceStatus
| GitPull of remote:IpAddress
@@ -122,7 +121,6 @@ type DiscoEvent =
| EnterJointConsensus _ -> "EnterJointConsensus"
| LeaderChanged _ -> "LeaderChanged"
| StateChanged _ -> "StateChanged"
- | PersistSnapshot _ -> "PersistSnapshot"
| RaftError _ -> "RaftError"
| Status _ -> "Status"
| SessionOpened _ -> "SessionOpened"
@@ -142,7 +140,6 @@ type DiscoEvent =
| EnterJointConsensus _
| LeaderChanged _
| StateChanged _
- | PersistSnapshot _
| RaftError _
| SessionOpened _
| SessionClosed _
@@ -166,7 +163,6 @@ type DiscoEvent =
// | _| | | | __/___) | |_| \__ \ || __/ | | | | |
// |_| |_|_|\___|____/ \__, |___/\__\___|_| |_| |_|
// |___/
-
| FileSystem _ -> Ignore
// ____ __ _
@@ -174,12 +170,10 @@ type DiscoEvent =
// | |_) / _` | |_| __|
// | _ < (_| | _| |_
// |_| \_\__,_|_| \__|
-
| ConfigurationDone _
| EnterJointConsensus _
| StateChanged _
| LeaderChanged _
- | PersistSnapshot _
| RaftError _ -> Process
// ____ _ _
@@ -187,7 +181,6 @@ type DiscoEvent =
// | | _| | __|
// | |_| | | |_
// \____|_|\__|
-
| GitPull _
| GitPush _ -> Process
@@ -196,7 +189,6 @@ type DiscoEvent =
// \ \ /\ / / _ \ '_ \___ \ / _ \ / __| |/ / _ \ __|
// \ V V / __/ |_) |__) | (_) | (__| < __/ |_
// \_/\_/ \___|_.__/____/ \___/ \___|_|\_\___|\__|
-
| SessionOpened _
| SessionClosed _ -> Replicate
@@ -209,7 +201,6 @@ type DiscoEvent =
// | _ \ / _` | __/ __| '_ \
// | |_) | (_| | || (__| | | |
// |____/ \__,_|\__\___|_| |_|
-
| Append (Origin.Client _, CommandBatch _)
| Append (Origin.Service _, CommandBatch _)
| Append (Origin.Web _, CommandBatch _) -> Replicate
@@ -220,7 +211,6 @@ type DiscoEvent =
// | | | | (_| | |_) | |_) | | | | | (_| |
// |_| |_|\__,_| .__/| .__/|_|_| |_|\__, |
// |_| |_| |___/
-
| Append (Origin.Client _, AddPinMapping _)
| Append (Origin.Service _, AddPinMapping _)
| Append (Origin.Web _, AddPinMapping _)
@@ -237,7 +227,6 @@ type DiscoEvent =
// \ V V / | | (_| | (_| | __/ |_
// \_/\_/ |_|\__,_|\__, |\___|\__|
// |___/
-
| Append (Origin.Client _, AddPinWidget _)
| Append (Origin.Service _, AddPinWidget _)
| Append (Origin.Web _, AddPinWidget _)
@@ -254,7 +243,6 @@ type DiscoEvent =
// | __/| | | (_) | | __/ (__| |_
// |_| |_| \___// |\___|\___|\__|
// |__/
-
| Append (Origin.Web _, UnloadProject) -> Replicate
| Append (Origin.Client _, UnloadProject) -> Ignore
| Append (Origin.Service _, UnloadProject) -> Replicate
@@ -268,23 +256,33 @@ type DiscoEvent =
// | |\/| |/ _ \ '_ ` _ \| '_ \ / _ \ '__|
// | | | | __/ | | | | | |_) | __/ |
// |_| |_|\___|_| |_| |_|_.__/ \___|_|
+ | Append (Origin.Web _, AddMachine _) -> Replicate
+ | Append (Origin.Web _, UpdateMachine _) -> Ignore
+ | Append (Origin.Web _, RemoveMachine _) -> Replicate
+ | Append (Origin.Client _, AddMachine _)
+ | Append (Origin.Client _, UpdateMachine _)
+ | Append (Origin.Client _, RemoveMachine _) -> Ignore
+ | Append (Origin.Service _, AddMachine _)
+ | Append (Origin.Service _, UpdateMachine _)
+ | Append (Origin.Service _, RemoveMachine _) -> Replicate
- | Append (Origin.Web _, AddMember _) -> Replicate
- | Append (Origin.Web _, UpdateMember _) -> Ignore
- | Append (Origin.Web _, RemoveMember _) -> Replicate
- | Append (Origin.Client _, AddMember _)
- | Append (Origin.Client _, UpdateMember _)
- | Append (Origin.Client _, RemoveMember _) -> Ignore
+ // __ __ _
+ // | \/ | ___ _ __ ___ | |__ ___ _ __
+ // | |\/| |/ _ \ '_ ` _ \| '_ \ / _ \ '__|
+ // | | | | __/ | | | | | |_) | __/ |
+ // |_| |_|\___|_| |_| |_|_.__/ \___|_|
| Append (Origin.Service _, AddMember _)
| Append (Origin.Service _, UpdateMember _)
| Append (Origin.Service _, RemoveMember _) -> Replicate
+ | Append ( _, AddMember _)
+ | Append ( _, UpdateMember _)
+ | Append ( _, RemoveMember _) -> Ignore
// ____ _ _ _
// / ___| (_) ___ _ __ | |_
// | | | | |/ _ \ '_ \| __|
// | |___| | | __/ | | | |_
// \____|_|_|\___|_| |_|\__|
-
| Append (Origin.Web _, AddClient _)
| Append (Origin.Web _, UpdateClient _)
| Append (Origin.Web _, RemoveClient _)
@@ -301,7 +299,6 @@ type DiscoEvent =
// | __/| | | | | |_| | | | (_) | |_| | |_) |
// |_| |_|_| |_|\____|_| \___/ \__,_| .__/
// |_|
-
| Append (Origin.Web _, AddPinGroup _)
| Append (Origin.Web _, UpdatePinGroup _)
| Append (Origin.Web _, RemovePinGroup _) -> Ignore
@@ -317,7 +314,6 @@ type DiscoEvent =
// | |_) | | '_ \
// | __/| | | | |
// |_| |_|_| |_|
-
| Append (Origin.Web _, AddPin _) -> Ignore
| Append (Origin.Web _, UpdatePin _) -> Replicate
| Append (Origin.Web _, RemovePin _) -> Ignore
@@ -333,7 +329,6 @@ type DiscoEvent =
// | | | | | |/ _ \
// | |__| |_| | __/
// \____\__,_|\___|
-
| Append (Origin.Web _, AddCue _)
| Append (Origin.Web _, UpdateCue _)
| Append (Origin.Web _, RemoveCue _)
@@ -377,7 +372,6 @@ type DiscoEvent =
// | | | | | |/ _ \ | | / __| __|
// | |__| |_| | __/ |___| \__ \ |_
// \____\__,_|\___|_____|_|___/\__|
-
| Append (Origin.Web _, AddCueList _)
| Append (Origin.Web _, UpdateCueList _)
| Append (Origin.Web _, RemoveCueList _)
@@ -394,7 +388,6 @@ type DiscoEvent =
// | |__| |_| | __/ __/| | (_| | |_| | __/ |
// \____\__,_|\___|_| |_|\__,_|\__, |\___|_|
// |___/
-
| Append (Origin.Web _, AddCuePlayer _)
| Append (Origin.Web _, UpdateCuePlayer _)
| Append (Origin.Web _, RemoveCuePlayer _)
@@ -410,7 +403,6 @@ type DiscoEvent =
// | | | / __|/ _ \ '__|
// | |_| \__ \ __/ |
// \___/|___/\___|_|
-
| Append (Origin.Web _, AddUser _)
| Append (Origin.Web _, UpdateUser _)
| Append (Origin.Web _, RemoveUser _) -> Replicate
@@ -426,7 +418,6 @@ type DiscoEvent =
// \___ \ / _ \/ __/ __| |/ _ \| '_ \
// ___) | __/\__ \__ \ | (_) | | | |
// |____/ \___||___/___/_|\___/|_| |_|
-
| Append (Origin.Web _, AddSession _)
| Append (Origin.Web _, UpdateSession _)
| Append (Origin.Web _, RemoveSession _) -> Replicate
@@ -442,7 +433,6 @@ type DiscoEvent =
// | | | | / __|/ __/ _ \ \ / / _ \ '__/ _ \/ _` |
// | |_| | \__ \ (_| (_) \ V / __/ | | __/ (_| |
// |____/|_|___/\___\___/ \_/ \___|_| \___|\__,_|
-
| Append (Origin.Web _, AddDiscoveredService _)
| Append (Origin.Web _, UpdateDiscoveredService _)
| Append (Origin.Web _, RemoveDiscoveredService _)
@@ -458,7 +448,6 @@ type DiscoEvent =
// | | | |/ _ \ / __| |/ /
// | |___| | (_) | (__| <
// \____|_|\___/ \___|_|\_\
-
| Append (Origin.Service _, UpdateClock _) -> Publish
| Append ( _, UpdateClock _) -> Ignore
@@ -467,7 +456,6 @@ type DiscoEvent =
// | | / _ \| '_ ` _ \| '_ ` _ \ / _` | '_ \ / _` |
// | |__| (_) | | | | | | | | | | | (_| | | | | (_| |
// \____\___/|_| |_| |_|_| |_| |_|\__,_|_| |_|\__,_|
-
| Append (Origin.Web _, Command _)
| Append (Origin.Client _, Command _)
| Append (Origin.Service _, Command _) -> Replicate
@@ -478,7 +466,6 @@ type DiscoEvent =
// | |_| | (_| | || (_| |___) | | | | (_| | |_) \__ \ | | | (_) | |_
// |____/ \__,_|\__\__,_|____/|_| |_|\__,_| .__/|___/_| |_|\___/ \__|
// |_|
-
| Append (Origin.Web _, DataSnapshot _)
| Append (Origin.Client _, DataSnapshot _)
| Append (Origin.Service _, DataSnapshot _) -> Ignore
@@ -488,7 +475,6 @@ type DiscoEvent =
// | |_ / _` / __| __| |_) | '__/ _ \ / __/ _ \/ __/ __|
// | _| (_| \__ \ |_| __/| | | (_) | (_| __/\__ \__ \
// |_| \__,_|___/\__|_| |_| \___/ \___\___||___/___/
-
| Append (_, UpdateSlices _) -> Publish
| Append (_, CallCue _) -> Publish
@@ -498,7 +484,6 @@ type DiscoEvent =
// | |__| (_) | (_| | | | \__ \ (_| |
// |_____\___/ \__, |_| |_|___/\__, |
// |___/ |___/
-
| Append (_, LogMsg _) -> Publish
// __ __ _
@@ -506,7 +491,6 @@ type DiscoEvent =
// | |\/| | / __|/ __|
// | | | | \__ \ (__
// |_| |_|_|___/\___|
-
| Append (_, SetLogLevel _) -> Replicate
// * DiscoEvent module
diff --git a/src/Disco/Disco/Core/IpAddress.fs b/src/Disco/Disco/Core/IpAddress.fs
index 727e4832..0bdf8de8 100644
--- a/src/Disco/Disco/Core/IpAddress.fs
+++ b/src/Disco/Disco/Core/IpAddress.fs
@@ -57,28 +57,28 @@ type IpAddress =
#if FABLE_COMPILER
try
IpAddress.Parse str
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
sprintf "Unable to parse IP: %s Cause: %s" str exn.Message
|> Disco.Core.Error.asParseError "IpAddress.Parse"
- |> Either.fail
+ |> Result.fail
#else
try
let ip = IPAddress.Parse(str)
match ip.AddressFamily with
- | Sockets.AddressFamily.InterNetwork -> IPv4Address str |> Right
- | Sockets.AddressFamily.InterNetworkV6 -> IPv6Address str |> Right
+ | Sockets.AddressFamily.InterNetwork -> IPv4Address str |> Ok
+ | Sockets.AddressFamily.InterNetworkV6 -> IPv6Address str |> Ok
| fam ->
sprintf "Unable to parse IP: %s Unsupported AddressFamily: %A" str fam
|> Error.asParseError "IpAddress.Parse"
- |> Either.fail
+ |> Result.fail
with
| exn ->
sprintf "Unable to parse IP: %s Cause: %s" str exn.Message
|> Error.asParseError "IpAddress.Parse"
- |> Either.fail
+ |> Result.fail
#endif
// ** ofIPAddress
diff --git a/src/Disco/Disco/Core/LogLevel.fs b/src/Disco/Disco/Core/LogLevel.fs
index eb2ae3d5..46ec5efe 100644
--- a/src/Disco/Disco/Core/LogLevel.fs
+++ b/src/Disco/Disco/Core/LogLevel.fs
@@ -34,7 +34,7 @@ type LogLevel =
| _ -> failwithf "could not parse %s" str
static member TryParse (str: string) =
- Either.tryWith ParseError "LogLevel" <| fun _ ->
+ Result.tryWith ParseError "LogLevel" <| fun _ ->
str |> LogLevel.Parse
override self.ToString() =
diff --git a/src/Disco/Disco/Core/Logging.fs b/src/Disco/Disco/Core/Logging.fs
index 0e2ad09f..b0f2fb17 100644
--- a/src/Disco/Disco/Core/Logging.fs
+++ b/src/Disco/Disco/Core/Logging.fs
@@ -58,7 +58,7 @@ type LogLevel =
// ** TryParse
static member TryParse (str: string) =
- Either.tryWith (Error.asParseError "LogLevel.TryParse") <| fun _ ->
+ Result.tryWith (Error.asParseError "LogLevel.TryParse") <| fun _ ->
str |> LogLevel.Parse
// ** ToString
@@ -108,7 +108,7 @@ type Tier =
// ** TryParse
static member TryParse (str: string) =
- Either.tryWith (Error.asParseError "Tier.TryParse") <| fun _ ->
+ Result.tryWith (Error.asParseError "Tier.TryParse") <| fun _ ->
str |> Tier.Parse
// * LogEventYaml
@@ -126,14 +126,32 @@ type LogEventYaml() =
#endif
+// * LogEventFields
+
+type LogEventFields =
+ { Time: bool
+ Thread: bool
+ Tier: bool
+ Id: bool
+ Tag: bool
+ LogLevel: bool
+ Message: bool }
+
+ // ** Default
+
+ static member Default =
+ { Time = true
+ Thread = true
+ Tier = true
+ Id = true
+ Tag = true
+ LogLevel = true
+ Message = true }
+
// * LogEvent
-/// ## LogEvent
-///
/// Structured log format record.
///
-/// ## Fields:
-///
/// - Time: int64 unixtime in milliseconds
/// - Thread: int ID of Thread the log event was collected
/// - Tier: application tier where log was collected
@@ -141,8 +159,7 @@ type LogEventYaml() =
/// - Tag: call site tag describing source code location where log was collected
/// - LogLevel: LogLevel of collected log message
/// - Message: log message
-///
-/// Returns: LogEvent
+
type LogEvent =
{ Time : uint32
Thread : int
@@ -192,7 +209,7 @@ type LogEvent =
// ** FromFB
- static member FromFB(fb: LogEventFB) = either {
+ static member FromFB(fb: LogEventFB) = result {
let! id = Id.decodeMachineId fb
let! tier = Tier.TryParse fb.Tier
let! level = LogLevel.TryParse fb.LogLevel
@@ -230,8 +247,8 @@ type LogEvent =
// ** FromYaml
- static member FromYaml(yaml: LogEventYaml) : Either =
- either {
+ static member FromYaml(yaml: LogEventYaml) : DiscoResult =
+ result {
let! id = DiscoId.TryParse yaml.MachineId
let! level = LogLevel.TryParse yaml.LogLevel
let! tier = Tier.TryParse yaml.Tier
@@ -254,6 +271,7 @@ type LoggingSettings =
{ MachineId: DiscoId
Level: LogLevel
UseColors: bool
+ Fields: LogEventFields
Tier: Tier }
// * LoggingSettings module
@@ -264,9 +282,10 @@ module LoggingSettings =
{ MachineId = DiscoId.Empty
Level = LogLevel.Debug
UseColors = true
+ Fields = LogEventFields.Default
Tier = Tier.Service }
-// * Logger
+// * Logger module
[]
module Logger =
@@ -283,7 +302,12 @@ module Logger =
{ MachineId = DiscoId.Empty
Level = LogLevel.Debug
UseColors = true
+ Fields = LogEventFields.Default
+ #if DISCO_NODES
+ Tier = Tier.Client }
+ #else
Tier = Tier.Service }
+ #endif
// ** currentSettings
@@ -293,6 +317,10 @@ module Logger =
let set config = _settings <- config
+ // ** setFields
+
+ let setFields fields = _settings <- { _settings with Fields = fields }
+
// ** setLevel
let setLevel level =
@@ -304,40 +332,41 @@ module Logger =
// ** stdout
- /// ## stdout
- ///
/// Simple logging to stdout
- ///
- /// ### Signature:
- /// - log: LogEvent
- ///
- /// Returns: unit
+
let stdout (log: LogEvent) =
#if !FABLE_COMPILER && !DISCO_NODES
if _settings.UseColors then
- Console.darkGreen "{0}" "["
- match log.LogLevel with
- | LogLevel.Trace -> Console.gray "{0,-5}" log.LogLevel
- | LogLevel.Debug -> Console.white "{0,-5}" log.LogLevel
- | LogLevel.Info -> Console.green "{0,-5}" log.LogLevel
- | LogLevel.Warn -> Console.yellow "{0,-5}" log.LogLevel
- | LogLevel.Err -> Console.red "{0,-5}" log.LogLevel
- Console.darkGreen "{0}" "] "
-
- Console.darkGreen "{0}:" "ts"
- Console.white "{0} " log.Time
-
- Console.darkGreen "{0}:" "id"
- Console.white "{0} " (log.MachineId.Prefix())
-
- Console.darkGreen "{0}:" "type"
- Console.white "{0,-7} " log.Tier
-
- Console.darkGreen "{0}:" "in"
- Console.yellow "{0,-30} " log.Tag
- Console.white "{0}" log.Message
- Console.Write(System.Environment.NewLine)
+ if _settings.Fields.LogLevel then
+ Console.darkGreen "{0}" "["
+ match log.LogLevel with
+ | LogLevel.Trace -> Console.gray "{0,-5}" log.LogLevel
+ | LogLevel.Debug -> Console.white "{0,-5}" log.LogLevel
+ | LogLevel.Info -> Console.green "{0,-5}" log.LogLevel
+ | LogLevel.Warn -> Console.yellow "{0,-5}" log.LogLevel
+ | LogLevel.Err -> Console.red "{0,-5}" log.LogLevel
+ Console.darkGreen "{0}" "] "
+
+ if _settings.Fields.Time then
+ Console.darkGreen "{0}:" "ts"
+ Console.white "{0} " log.Time
+
+ if _settings.Fields.Id then
+ Console.darkGreen "{0}:" "id"
+ Console.white "{0} " (log.MachineId.Prefix())
+
+ if _settings.Fields.Tier then
+ Console.darkGreen "{0}:" "type"
+ Console.white "{0,-7} " log.Tier
+
+ if _settings.Fields.Tag then
+ Console.darkGreen "{0}:" "in"
+ Console.yellow "{0,-30} " log.Tag
+
+ if _settings.Fields.Message then
+ Console.white "{0}" log.Message
+ Console.Write(System.Environment.NewLine)
else
#endif
Console.WriteLine("{0}", log)
@@ -577,24 +606,24 @@ module LogFile =
log
|> string
|> file.Stream.WriteLine
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asIOError (tag "write")
- |> Either.fail
+ |> Result.fail
// ** create
let create (machine: MachineId) (path: FilePath) =
- either {
+ result {
try
let ts = DateTime.Now
let fn = String.Format("disco-{0}-{1:yyyy-MM-dd_hh-mm-ss-tt}.log", machine.Prefix(), ts)
do! if Directory.exists path |> not then
Directory.createDirectory path
- |> Either.ignore
- else Either.succeed ()
+ |> Result.ignore
+ else Result.succeed ()
let fp = Path.Combine(unwrap path, fn)
let writer = File.AppendText fp
writer.AutoFlush <- true
@@ -607,7 +636,7 @@ module LogFile =
return!
exn.Message
|> Error.asIOError (tag "create")
- |> Either.fail
+ |> Result.fail
}
#endif
diff --git a/src/Disco/Disco/Core/Machine.fs b/src/Disco/Disco/Core/Machine.fs
index 2a6ca97e..4c4f9b41 100644
--- a/src/Disco/Disco/Core/Machine.fs
+++ b/src/Disco/Disco/Core/Machine.fs
@@ -165,7 +165,7 @@ type DiscoMachine =
// ** FromFB
static member FromFB (fb: DiscoMachineFB) =
- either {
+ result {
let! machineId = Id.decodeMachineId fb
let! ip = IpAddress.TryParse fb.BindAddress
let! metricsHost = IpAddress.TryParse fb.MetricsHost
@@ -246,7 +246,7 @@ type DiscoMachineYaml () =
[] val mutable AssetFilter: string
[] val mutable LogDirectory: string
[] val mutable CollectMetrics: bool
-
+
[] val mutable MetricsHost: string
[] val mutable MetricsPort: uint16
@@ -272,8 +272,8 @@ type DiscoMachineYaml () =
yml.LogDirectory <- unwrap cfg.LogDirectory
yml.CollectMetrics <- cfg.CollectMetrics
yml.MetricsHost <- string cfg.MetricsHost
- yml.MetricsPort <- unwrap cfg.MetricsPort
- yml.MetricsDb <- cfg.MetricsDb
+ yml.MetricsPort <- unwrap cfg.MetricsPort
+ yml.MetricsDb <- cfg.MetricsDb
yml.BindAddress <- string cfg.BindAddress
yml.MulticastAddress <- string cfg.MulticastAddress
yml.MulticastPort <- unwrap cfg.MulticastPort
@@ -334,28 +334,28 @@ module MachineStatus =
static member FromFB(fb: MachineStatusFB) =
#if FABLE_COMPILER
match fb.Status with
- | x when x = MachineStatusEnumFB.IdleFB -> Either.succeed Idle
+ | x when x = MachineStatusEnumFB.IdleFB -> Result.succeed Idle
| x when x = MachineStatusEnumFB.BusyFB ->
- either {
+ result {
let! id = Id.decodeProjectId fb
return Busy (id, name fb.ProjectName)
}
| other ->
sprintf "Unknown Machine Status: %d" other
|> Error.asParseError "MachineStatus.FromOffset"
- |> Either.fail
+ |> Result.fail
#else
match fb.Status with
- | MachineStatusEnumFB.IdleFB -> Either.succeed Idle
+ | MachineStatusEnumFB.IdleFB -> Result.succeed Idle
| MachineStatusEnumFB.BusyFB ->
- either {
+ result {
let! id = Id.decodeProjectId fb
return Busy (id, name fb.ProjectName)
}
| other ->
sprintf "Unknown Machine Status: %O" other
|> Error.asParseError "MachineStatus.FromOffset"
- |> Either.fail
+ |> Result.fail
#endif
// *** ToBytes
@@ -452,8 +452,8 @@ module MachineConfig =
// ** parse
- let private parse (yml: DiscoMachineYaml) : Either =
- either {
+ let private parse (yml: DiscoMachineYaml) : DiscoResult =
+ result {
let! ip = IpAddress.TryParse yml.BindAddress
let! metricsHost = IpAddress.TryParse yml.MetricsHost
let! id = DiscoId.TryParse yml.MachineId
@@ -556,7 +556,7 @@ module MachineConfig =
// ** save
- let save (path: FilePath option) (cfg: DiscoMachine) : Either =
+ let save (path: FilePath option) (cfg: DiscoMachine) : DiscoResult =
let serializer = Serializer()
try
@@ -573,12 +573,12 @@ module MachineConfig =
|> ensureExists
File.WriteAllText(unwrap location, payload)
- |> Either.succeed
+ |> Result.succeed
with
| exn ->
exn.Message
|> Error.asIOError (tag "save")
- |> Either.fail
+ |> Result.fail
// ** load
@@ -594,16 +594,16 @@ module MachineConfig =
else
"could not find machine configuration"
|> Error.asIOError (tag "load")
- |> Either.fail
+ |> Result.fail
with exn ->
exn.Message
|> Error.asIOError (tag "load")
- |> Either.fail
+ |> Result.fail
// ** init
/// Attention: this method must be called only when starting the main process
- let init getBindIp shiftDefaults (path: FilePath option) : Either =
+ let init getBindIp shiftDefaults (path: FilePath option) : DiscoResult =
let serializer = Serializer()
try
let location = getLocation path
@@ -617,11 +617,11 @@ module MachineConfig =
let bindIp = getBindIp()
let cfg = create bindIp shiftDefaults
save path cfg
- |> Either.map (fun _ -> cfg)
+ |> Result.map (fun _ -> cfg)
match cfg with
- | Left err -> Either.fail err
- | Right cfg ->
+ | Error err -> Result.fail err
+ | Ok cfg ->
if Path.IsPathRooted (unwrap cfg.WorkSpace)
then singleton <- cfg
else
@@ -631,12 +631,12 @@ module MachineConfig =
|> filepath
> cfg.WorkSpace
singleton <- { cfg with WorkSpace = wp }
- Either.succeed()
+ Result.succeed()
with
| exn ->
exn.Message
|> Error.asIOError (tag "load")
- |> Either.fail
+ |> Result.fail
#endif
diff --git a/src/Disco/Disco/Core/Metrics.fs b/src/Disco/Disco/Core/Metrics.fs
index d3b2154e..a4246799 100644
--- a/src/Disco/Disco/Core/Metrics.fs
+++ b/src/Disco/Disco/Core/Metrics.fs
@@ -23,11 +23,11 @@ module Metrics =
.WriteTo.InfluxDB(url, config.MetricsDb)
.CreateCollector()
- let init (config: DiscoMachine): Either =
+ let init (config: DiscoMachine): DiscoResult =
try
if config.CollectMetrics then
match agent with
- | Some _ -> Either.nothing
+ | Some _ -> Result.nothing
| None ->
let collector = createCollector config
let actor = ThreadActor.create "Metrics" (fun _ (name,value) ->
@@ -36,12 +36,12 @@ module Metrics =
do collector.Write(name, values))
actor.Start()
agent <- Some actor
- Either.nothing
- else Either.nothing
+ Result.nothing
+ else Result.nothing
with exn ->
exn.Message
|> Error.asIOError "Metrics.init"
- |> Either.fail
+ |> Result.fail
let collect (name: string) (value: obj) : unit =
match agent with
diff --git a/src/Disco/Disco/Core/Network.fs b/src/Disco/Disco/Core/Network.fs
index 48e421ad..1e3f1c24 100644
--- a/src/Disco/Disco/Core/Network.fs
+++ b/src/Disco/Disco/Core/Network.fs
@@ -130,13 +130,13 @@ module Network =
List.fold
(fun result (iface: NetworkInterface) ->
match result with
- | Right () -> result
- | Left _ ->
+ | Ok () -> result
+ | Error _ ->
if List.contains ip iface.IpAddresses then
- Either.succeed ()
+ Result.succeed ()
else
result)
- (Left (Error.asSocketError (tag "checkIpAddress") msg))
+ (Error (Error.asSocketError (tag "checkIpAddress") msg))
ifaces
// ** ensureIpAddress
@@ -160,7 +160,7 @@ module Network =
// ** ensureAvailability
let ensureAvailability (ip: IpAddress) (port: Port) =
- either {
+ result {
try
use socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
let endpoint = IPEndPoint(ip.toIPAddress(), int port)
@@ -174,7 +174,7 @@ module Network =
port
|> sprintf "Address %O:%O already in use" ip
|> Error.asSocketError (tag "ensureAvailability")
- |> Either.fail
+ |> Result.fail
}
#endif
diff --git a/src/Disco/Disco/Core/Pin.fs b/src/Disco/Disco/Core/Pin.fs
index e9c30686..b779f80b 100644
--- a/src/Disco/Disco/Core/Pin.fs
+++ b/src/Disco/Disco/Core/Pin.fs
@@ -63,16 +63,16 @@ type Behavior =
static member TryParse (str: string) =
match String.toLower str with
- | "string" | "simple" -> Right Simple
- | "multiline" -> Right MultiLine
- | "filename" -> Right FileName
- | "directory" -> Right Directory
- | "url" -> Right Url
- | "ip" -> Right IP
+ | "string" | "simple" -> Ok Simple
+ | "multiline" -> Ok MultiLine
+ | "filename" -> Ok FileName
+ | "directory" -> Ok Directory
+ | "url" -> Ok Url
+ | "ip" -> Ok IP
| _ ->
sprintf "Invalid Behavior value: %s" str
|> Error.asParseError "Behavior.TryParse"
- |> Either.fail
+ |> Result.fail
// ** ToString
@@ -97,30 +97,30 @@ type Behavior =
static member FromFB (fb: BehaviorFB) =
#if FABLE_COMPILER
match fb with
- | x when x = BehaviorFB.SimpleFB -> Right Simple
- | x when x = BehaviorFB.MultiLineFB -> Right MultiLine
- | x when x = BehaviorFB.FileNameFB -> Right FileName
- | x when x = BehaviorFB.DirectoryFB -> Right Directory
- | x when x = BehaviorFB.UrlFB -> Right Url
- | x when x = BehaviorFB.IPFB -> Right IP
+ | x when x = BehaviorFB.SimpleFB -> Ok Simple
+ | x when x = BehaviorFB.MultiLineFB -> Ok MultiLine
+ | x when x = BehaviorFB.FileNameFB -> Ok FileName
+ | x when x = BehaviorFB.DirectoryFB -> Ok Directory
+ | x when x = BehaviorFB.UrlFB -> Ok Url
+ | x when x = BehaviorFB.IPFB -> Ok IP
| x ->
sprintf "Cannot parse Behavior. Unknown type: %A" x
|> Error.asParseError "Behavior.FromFB"
- |> Either.fail
+ |> Result.fail
#else
match fb with
- | BehaviorFB.SimpleFB -> Right Simple
- | BehaviorFB.MultiLineFB -> Right MultiLine
- | BehaviorFB.FileNameFB -> Right FileName
- | BehaviorFB.DirectoryFB -> Right Directory
- | BehaviorFB.UrlFB -> Right Url
- | BehaviorFB.IPFB -> Right IP
+ | BehaviorFB.SimpleFB -> Ok Simple
+ | BehaviorFB.MultiLineFB -> Ok MultiLine
+ | BehaviorFB.FileNameFB -> Ok FileName
+ | BehaviorFB.DirectoryFB -> Ok Directory
+ | BehaviorFB.UrlFB -> Ok Url
+ | BehaviorFB.IPFB -> Ok IP
| x ->
sprintf "Cannot parse Behavior. Unknown type: %A" x
|> Error.asParseError "Behavior.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
@@ -177,12 +177,12 @@ type PinConfiguration =
try
str
|> PinConfiguration.Parse
- |> Either.succeed
+ |> Result.succeed
with
| x ->
x.Message
|> Error.asParseError "PinConfiguration.TryParse"
- |> Either.fail
+ |> Result.fail
// ** ToOffset
@@ -197,22 +197,22 @@ type PinConfiguration =
static member FromFB(fb: PinConfigurationFB) =
#if FABLE_COMPILER
match fb with
- | x when x = PinConfigurationFB.SinkFB -> Right Sink
- | x when x = PinConfigurationFB.SourceFB -> Right Source
- | x when x = PinConfigurationFB.PresetFB -> Right Preset
+ | x when x = PinConfigurationFB.SinkFB -> Ok Sink
+ | x when x = PinConfigurationFB.SourceFB -> Ok Source
+ | x when x = PinConfigurationFB.PresetFB -> Ok Preset
| x ->
sprintf "Unknown PinConfigurationFB value: %A" x
|> Error.asParseError "PinConfiguration.FromFB"
- |> Either.fail
+ |> Result.fail
#else
match fb with
- | PinConfigurationFB.SinkFB -> Right Sink
- | PinConfigurationFB.SourceFB -> Right Source
- | PinConfigurationFB.PresetFB -> Right Preset
+ | PinConfigurationFB.SinkFB -> Ok Sink
+ | PinConfigurationFB.SourceFB -> Ok Source
+ | PinConfigurationFB.PresetFB -> Ok Preset
| x ->
sprintf "Unknown PinConfigurationFB value: %A" x
|> Error.asParseError "PinConfiguration.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
// * VecSize
@@ -256,12 +256,12 @@ type VecSize =
try
str
|> VecSize.Parse
- |> Either.succeed
+ |> Result.succeed
with
| x ->
x.Message
|> Error.asParseError "VecSize.TryParse"
- |> Either.fail
+ |> Result.fail
// ** ToOffset
@@ -282,21 +282,21 @@ type VecSize =
static member FromFB(fb: VecSizeFB) =
#if FABLE_COMPILER
match fb.Type with
- | x when x = VecSizeTypeFB.DynamicFB -> Right Dynamic
+ | x when x = VecSizeTypeFB.DynamicFB -> Ok Dynamic
| x when x = VecSizeTypeFB.FixedFB ->
- Right (Fixed fb.Size)
+ Ok (Fixed fb.Size)
| x ->
sprintf "Unknown VecSizeFB value: %A" x
|> Error.asParseError "VecSize.FromFB"
- |> Either.fail
+ |> Result.fail
#else
match fb.Type with
- | VecSizeTypeFB.DynamicFB -> Right Dynamic
- | VecSizeTypeFB.FixedFB -> Right (Fixed fb.Size)
+ | VecSizeTypeFB.DynamicFB -> Ok Dynamic
+ | VecSizeTypeFB.FixedFB -> Ok (Fixed fb.Size)
| x ->
sprintf "Unknown PinConfigurationFB value: %A" x
|> Error.asParseError "PinConfiguration.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
// * Pin
@@ -506,49 +506,49 @@ type Pin =
// ** FromFB
- static member FromFB(fb: PinFB) : Either =
+ static member FromFB(fb: PinFB) : DiscoResult =
#if FABLE_COMPILER
match fb.PinType with
| x when x = PinTypeFB.StringPinFB ->
StringPinFB.Create()
|> fb.Pin
|> StringPinD.FromFB
- |> Either.map StringPin
+ |> Result.map StringPin
| x when x = PinTypeFB.NumberPinFB ->
NumberPinFB.Create()
|> fb.Pin
|> NumberPinD.FromFB
- |> Either.map NumberPin
+ |> Result.map NumberPin
| x when x = PinTypeFB.BoolPinFB ->
BoolPinFB.Create()
|> fb.Pin
|> BoolPinD.FromFB
- |> Either.map BoolPin
+ |> Result.map BoolPin
| x when x = PinTypeFB.BytePinFB ->
BytePinFB.Create()
|> fb.Pin
|> BytePinD.FromFB
- |> Either.map BytePin
+ |> Result.map BytePin
| x when x = PinTypeFB.EnumPinFB ->
EnumPinFB.Create()
|> fb.Pin
|> EnumPinD.FromFB
- |> Either.map EnumPin
+ |> Result.map EnumPin
| x when x = PinTypeFB.ColorPinFB ->
ColorPinFB.Create()
|> fb.Pin
|> ColorPinD.FromFB
- |> Either.map ColorPin
+ |> Result.map ColorPin
| x ->
sprintf "%A is not a valid PinTypeFB" x
|> Error.asParseError "PinFB.FromFB"
- |> Either.fail
+ |> Result.fail
#else
@@ -558,71 +558,71 @@ type Pin =
if v.HasValue then
v.Value
|> StringPinD.FromFB
- |> Either.map StringPin
+ |> Result.map StringPin
else
"StringPinFB has no value"
|> Error.asParseError "PinFB.FromFB"
- |> Either.fail
+ |> Result.fail
| PinTypeFB.NumberPinFB ->
let v = fb.Pin()
if v.HasValue then
v.Value
|> NumberPinD.FromFB
- |> Either.map NumberPin
+ |> Result.map NumberPin
else
"NumberPinFB has no value"
|> Error.asParseError "PinFB.FromFB"
- |> Either.fail
+ |> Result.fail
| PinTypeFB.BoolPinFB ->
let v = fb.Pin()
if v.HasValue then
v.Value
|> BoolPinD.FromFB
- |> Either.map BoolPin
+ |> Result.map BoolPin
else
"BoolPinFB has no value"
|> Error.asParseError "PinFB.FromFB"
- |> Either.fail
+ |> Result.fail
| PinTypeFB.BytePinFB ->
let v = fb.Pin()
if v.HasValue then
v.Value
|> BytePinD.FromFB
- |> Either.map BytePin
+ |> Result.map BytePin
else
"BytePinFB has no value"
|> Error.asParseError "PinFB.FromFB"
- |> Either.fail
+ |> Result.fail
| PinTypeFB.EnumPinFB ->
let v = fb.Pin()
if v.HasValue then
v.Value
|> EnumPinD.FromFB
- |> Either.map EnumPin
+ |> Result.map EnumPin
else
"EnumPinFB has no value"
|> Error.asParseError "PinFB.FromFB"
- |> Either.fail
+ |> Result.fail
| PinTypeFB.ColorPinFB ->
let v = fb.Pin()
if v.HasValue then
v.Value
|> ColorPinD.FromFB
- |> Either.map ColorPin
+ |> Result.map ColorPin
else
"ColorPinFB has no value"
|> Error.asParseError "PinFB.FromFB"
- |> Either.fail
+ |> Result.fail
| x ->
sprintf "PinTypeFB not recognized: %A" x
|> Error.asParseError "PinFB.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
@@ -632,7 +632,7 @@ type Pin =
// ** FromBytes
- static member FromBytes(bytes: byte[]) : Either =
+ static member FromBytes(bytes: byte[]) : DiscoResult =
Binary.createBuffer bytes
|> PinFB.GetRootAsPinFB
|> Pin.FromFB
@@ -666,63 +666,64 @@ module Pin =
#if FABLE_COMPILER
- let inline parseComplexValues< ^a, ^b, ^t when ^t : (static member FromFB : ^a -> Either)
+ let inline parseComplexValues< ^a, ^b, ^t when ^t : (static member FromFB : ^a -> DiscoResult< ^t>)
and ^b : (member ValuesLength : int)
and ^b : (member Values : int -> ^a)>
(fb: ^b)
- : Either =
+ : DiscoResult< ^t array> =
let len = (^b : (member ValuesLength : int) fb)
let arr = Array.zeroCreate len
Array.fold
- (fun (result: Either) _ -> either {
-
- let! (i, slices) = result
+ (fun (res: DiscoResult) _ ->
+ result {
+ let! (i, slices) = res
// In Javascript, Flatbuffer types are not modeled as nullables,
// hence parsing code is much simpler
let! slice =
let value = (^b : (member Values : int -> ^a) (fb, i))
- (^t : (static member FromFB : ^a -> Either) value)
+ (^t : (static member FromFB : ^a -> DiscoResult< ^t>) value)
// add the slice to the array> at its correct position
slices.[i] <- slice
return (i + 1, slices)
})
- (Right (0, arr))
+ (Ok (0, arr))
arr
- |> Either.map snd
+ |> Result.map snd
#else
- let inline parseComplexValues< ^a, ^b, ^t when ^t : (static member FromFB : ^a -> Either)
+ let inline parseComplexValues< ^a, ^b, ^t when ^t : (static member FromFB : ^a -> DiscoResult< ^t>)
and ^b : (member ValuesLength : int)
and ^b : (member Values : int -> Nullable< ^a >)>
(fb: ^b)
- : Either =
+ : DiscoResult< ^t array> =
let len = (^b : (member ValuesLength : int) fb)
let arr = Array.zeroCreate len
Array.fold
- (fun (result: Either) _ -> either {
- let! (i, slices) = result
+ (fun (res: DiscoResult) _ ->
+ result {
+ let! (i, slices) = res
// In .NET, Flatbuffers are modelled with nullables, hence
// parsing is slightly more elaborate
let! slice =
let value = (^b : (member Values : int -> Nullable< ^a >) (fb, i))
if value.HasValue then
- (^t : (static member FromFB : ^a -> Either) value.Value)
+ (^t : (static member FromFB : ^a -> DiscoResult< ^t>) value.Value)
else
"Could not parse empty slice"
|> Error.asParseError (sprintf "ParseSlices of %s" (typeof< ^t >).Name)
- |> Either.fail
+ |> Result.fail
// add the slice to the array> at its correct position
slices.[i] <- slice
return (i + 1, slices)
})
- (Right (0, arr))
+ (Ok (0, arr))
arr
- |> Either.map snd
+ |> Result.map snd
#endif
@@ -733,37 +734,35 @@ module Pin =
let inline parseSimpleValues< ^a, ^b when ^b : (member ValuesLength : int)
and ^b : (member Values : int -> ^a)>
(fb: ^b)
- : Either =
+ : DiscoResult< ^a array> =
let len = (^b : (member ValuesLength : int) fb)
let arr = Array.zeroCreate len
Array.fold
- (fun (result: Either) _ -> either {
-
- let! (i, slices) = result
-
+ (fun (res: DiscoResult) _ ->
+ result {
+ let! (i, slices) = res
// In Javascript, Flatbuffer types are not modeled as nullables,
// hence parsing code is much simpler
let slice = (^b : (member Values : int -> ^a) (fb, i))
-
// add the slice to the array> at its correct position
slices.[i] <- slice
return (i + 1, slices)
})
- (Right (0, arr))
+ (Ok (0, arr))
arr
- |> Either.map snd
+ |> Result.map snd
#else
let inline parseSimpleValues< ^a, ^b when ^b : (member ValuesLength : int)
and ^b : (member Values : int -> ^a)>
(fb: ^b)
- : Either =
+ : DiscoResult< ^a array> =
let len = (^b : (member ValuesLength : int) fb)
let arr = Array.zeroCreate len
Array.fold
- (fun (result: Either) _ -> either {
- let! (i, slices) = result
+ (fun (res: DiscoResult) _ -> result {
+ let! (i, slices) = res
// In .NET, Flatbuffers are modelled with nullables, hence
// parsing is slightly more elaborate
@@ -775,9 +774,9 @@ module Pin =
slices.[i] <- slice
return (i + 1, slices)
})
- (Right (0, arr))
+ (Ok (0, arr))
arr
- |> Either.map snd
+ |> Result.map snd
#endif
@@ -796,7 +795,7 @@ module Pin =
else
"Cannot parse empty VecSize"
|> Error.asParseError "VecSize.FromFB"
- |> Either.fail
+ |> Result.fail
#endif
// ** parseLabels
@@ -805,21 +804,21 @@ module Pin =
let inline parseLabels< ^a when ^a : (member LabelsLength : int)
and ^a : (member Labels : int -> string)>
(fb: ^a)
- : Either