public static void InverseFunctions() { #region "Inverse function 1" Func <double, double> lg = x => Math.Log(x, 2.0); Func <double, double> powerOf2 = x => Math.Pow(2.0, x); Console.WriteLine(lg(8.0)); Console.WriteLine(powerOf2(3.0)); Console.WriteLine(Compose(powerOf2, lg)(8.0)); Console.WriteLine(Compose(lg, powerOf2)(3.0)); #endregion #region "Inverse function 2" var msg0 = new Msg(a: "Hello World", b: 123, c: 456.789); Console.WriteLine(msg0); var json0 = SerializationUtil.SerializeToJson(msg0); Console.WriteLine(json0); var msg1 = SerializationUtil.DeserializeFromJson <Msg>(json0); Console.WriteLine(msg1); Func <string, Msg> g = x => SerializationUtil.DeserializeFromJson <Msg>(x); Func <Msg, string> f = x => SerializationUtil.SerializeToJson(x); var msg2 = Compose(g, f)(msg0); Console.WriteLine(msg2); #endregion }
public static void Main() { var xs = new[] { 1, 2, 3, 4 }; //Create a lambda with 2 arguments. var length0 = Foldl <int, int>((acc, x) => acc + 1, 0, xs); Console.WriteLine("length0: " + length0.ToString()); // //Create a lambda with 2 arguments. var length1 = Foldl <int, int>(acc => x => acc + 1, 0, xs); Console.WriteLine("length1: " + length1.ToString()); //Explicitly use `acc` and `x` var length2 = Foldl <int, int>((acc, x) => Const(acc + 1)(x), 0, xs); Console.WriteLine("length2: " + length2.ToString()); //Drop `x` but having our lambda return a `Func<int,int>`, //rather than a `Func<int,int,int>`. var length3 = Foldl <int, int>(acc => Const(acc + 1), 0, xs); Console.WriteLine("length3: " + length3.ToString()); //Drop `acc` by having using a `Func<int,Func<int,int>>` as our lambda, //instead of a `Func<int,int,int>`. var length4 = Foldl <int, int>(acc => Compose <int, int, Func <int, int> >(Const, Succ)(acc), 0, xs); Console.WriteLine("length4: " + length4.ToString()); var length5 = Foldl <int, int>(Compose <int, int, Func <int, int> >(Const, Succ), 0, xs); Console.WriteLine("length5: " + length5.ToString()); }
static void Chapter2() { // Exercise 2.1, 2.2 Console.WriteLine(Compose(Triple, Square)(5)); // 75 // Exercise 2.3 Console.WriteLine(Add(2)(3)); // 5 var add2To = Add(2); Console.WriteLine(add2To(3)); // 5 var multiply2By = Mul(2); Console.WriteLine(multiply2By(3)); // 6 BinaryOperator sub = a => b => a - b; var from2Subtract = sub(2); Console.WriteLine(from2Subtract(3)); // -1 // Exercise 2.5 var tripleSquare = CurryCompose <int, int, int>()(Triple)(Square); Console.WriteLine(tripleSquare(5)); // 75 // Exercise 2.6 var tripleSquareFlipped = HigherAndThen <int, int, int>()(Square)(Triple); Console.WriteLine(tripleSquareFlipped(5)); // 75 // Exercise 2.7 & 8 Func <int, Func <int, int> > add = a => b => a + b; var add2Partial = PartialBoth(2, add); Console.WriteLine(add2Partial(3)); //5 // Exercise 2.9 var formatStrings = F <int, double, long, short>(); var formattedString = formatStrings(42)(52.7)(42L)(1); Console.WriteLine(formattedString); // duh... // Exercise 2.10 Func <Tuple <int, double>, string> tupleMul = t => $"{t.Item1 * t.Item2}"; Console.WriteLine(Curry(tupleMul)(6)(7)); // 42 // Exercise 2.11 Func <double, Func <double, double> > addTax = x => y => x + x / 100 * y; Func <double, Func <double, double> > swaapp(Func <double, Func <double, double> > f) => y => x => f(x)(y); Console.WriteLine(swaapp(addTax)(0.09)(42.00)); // 42.0378 // Exercise 2.12 Console.WriteLine(Factorial(5)); // 120 }
public ComposedPipeline(IEnumerable <IHubPipelineModule> modules) { // This wouldn't look nearly as gnarly if C# had better type inference, but now we don't need the ComposedModule or PassThroughModule. Invoke = Compose <Func <IHubIncomingInvokerContext, Task <object> > >(modules, (m, f) => m.BuildIncoming(f))(HubDispatcher.Incoming); Connect = Compose <Func <IHub, Task> >(modules, (m, f) => m.BuildConnect(f))(HubDispatcher.Connect); Reconnect = Compose <Func <IHub, Task> >(modules, (m, f) => m.BuildReconnect(f))(HubDispatcher.Reconnect); Disconnect = Compose <Func <IHub, bool, Task> >(modules, (m, f) => m.BuildDisconnect(f))(HubDispatcher.Disconnect); AuthorizeConnect = Compose <Func <HubDescriptor, HttpRequest, bool> >(modules, (m, f) => m.BuildAuthorizeConnect(f))((h, r) => true); RejoiningGroups = Compose <Func <HubDescriptor, HttpRequest, IList <string>, IList <string> > >(modules, (m, f) => m.BuildRejoiningGroups(f))((h, r, g) => g); Send = Compose <Func <IHubOutgoingInvokerContext, Task> >(modules, (m, f) => m.BuildOutgoing(f))(HubDispatcher.Outgoing); }
public void CanFindExportableCtor() { //Arrange Compose <IAnimal> .Exports.Clear(); Compose <IManager> .Exports.Clear(); Compose <IZoo> .Exports.Clear(); Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Dog)); Compose <IAnimal> .Add(typeof(Cat)); Compose <IZoo> .Add(typeof(DallasZoo)); Compose <IManager> .Add(typeof(MrJones)); //Act var ctorInfo = typeof(Cat).GetExportableConstructor(); // Assert Assert.True(ctorInfo != null); }
private void ReplyButton_Click(object sender, RoutedEventArgs e) { var Compose = new Compose(_mvm, ExtractEmail(), $"Re: {emailSubject.Text}"); Compose.Show(); Close(); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { var id = ""; var data = ""; Curve innerBounds = null; Curve outerBounds = null; DA.GetData(0, ref id); DA.GetData(1, ref data); DA.GetData(2, ref innerBounds); DA.GetData(3, ref outerBounds); var req = new CiceroRequest(data, innerBounds, outerBounds); SolutionManifest res = Parse.Request(req); res.RunContainment(); res.RunVerbs(); res.RunAdverbs(); var dwg = Compose.Drawing(res); dwg.Build(); var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\cicero\\svg\\" + id + ".svg"; io.File.WriteAllText(path, dwg.SvgText.ToString()); var crvs = new List <Curve>(); res.BoxElements.ForEach(x => x.InputSegments.ForEach(y => crvs.Add(y))); DA.SetDataList(0, res.InputLines); }
/** * /// Phoneticize a word * /// * /// @param entry * /// the word to phoneticize transformed to an ArrayList of Strings * /// (each element hold a single character) * /// @param nbest * /// the number of distinct pronunciations to return * /// @return the pronunciation(s) of the input word */ public List <Path> Phoneticize(List <String> entry, int nbest) { var efst = EntryToFsa(entry); var s = efst.Semiring; Compose.Augment(1, efst, s); ArcSort.Apply(efst, new OLabelCompare()); var result = Compose.compose(efst, _epsilonFilter, s, true); ArcSort.Apply(result, new OLabelCompare()); result = Compose.compose(result, _g2Pmodel, s, true); Project.Apply(result, ProjectType.Output); if (nbest == 1) { result = NShortestPaths.Get(result, 1, false); } else { // Requesting 10 times more best paths than what was asking // as there might be several paths resolving to same pronunciation // due to epsilon transitions. // I really hate cosmological constants :) result = NShortestPaths.Get(result, nbest * 10, false); } // result = NShortestPaths.get(result, nbest, false); result = RmEpsilon.Get(result); var paths = FindAllPaths(result, nbest, _skipSeqs, Tie); return(paths); }
public void WithArguments() { // Arrange var data = Utils.JsonNumberArray(1, 2, 3); var op = Compose.AllParams( new FunctionDefinition { Name = "x", Arguments = new List <string>() { "test1", "test2" }, Body = new ConstructArray { Elements = Concat.AllParams( FunctionCall.ZeroArity("test1"), FunctionCall.ZeroArity("test2")) } }, new FunctionCall(new FunctionName("x", 2), new Enumerate(), new Identity())); // Act var result = op.RunAsScalar(data); // Assert var expectedValues = Json.ArrayParams( Json.Number(1), Json.Number(2), Json.Number(3), Utils.JsonNumberArray(1, 2, 3)); result.DeepEqual(expectedValues).Should().BeTrue(); }
private static IEnumerable <TestItem> PipeTests() { yield return(new TestItem(". | .", Compose.AllParams( new Identity(), new Identity()))); yield return(new TestItem(". | . | .", Compose.AllParams( new Identity(), new Identity(), new Identity()))); yield return(new TestItem(". | . | . | .", Compose.AllParams( new Identity(), new Identity(), new Identity(), new Identity()))); yield return(new TestItem(".a | .[].c | .d", Compose.AllParams( new StringSelector { Key = "a" }, Compose.AllParams( new Enumerate(), new StringSelector { Key = "c" } ), new StringSelector { Key = "d" }))); }
private static IEnumerable <TestItem> CommaTests() { yield return(new TestItem("1, 2", Concat.AllParams( new Literal(1), new Literal(2) ))); yield return(new TestItem("1, 2, \"a\"", Concat.AllParams( new Literal(1), new Literal(2), new Literal("a") ))); yield return(new TestItem( "1, 2, \"a\" | . | 3, 4", Compose.AllParams( Concat.AllParams( new Literal(1), new Literal(2), new Literal("a")), new Identity(), Concat.AllParams( new Literal(3), new Literal { Value = Json.Number(4) })))); }
private static IEnumerable <TestItem> ParenTests() { yield return(new TestItem( "1 + (1 - 1)", new FunctionCall( Plus.Builtin, new Literal(1), new FunctionCall( Minus.Builtin_2, new Literal(1), new Literal(1))))); yield return(new TestItem("(. | .) | .", Compose.AllParams( Compose.AllParams( new Identity(), new Identity()), new Identity() ))); yield return(new TestItem( "(1 + 2) * 2", new FunctionCall( Times.Builtin, new FunctionCall( Plus.Builtin, new Literal(1), new Literal(2)), new Literal(2)))); }
public void ConstructObjectTestTwoKeys() { // Arrange var data = MakeArray(); var op = new Compose { First = new Enumerate(), Second = new ConstructObject( new PropertyDescriptor(new Literal("a"), new Identity()), new PropertyDescriptor(new Literal("b"), new Identity())) }; // Act var result = op.RunAsSequence(data); // Assert Json.Array(result) .DeepEqual(Json.ArrayParams( Json.ObjectParams( new JsonProperty("a", Json.Number(1)), new JsonProperty("b", Json.Number(1))), Json.ObjectParams( new JsonProperty("a", Json.Number(2)), new JsonProperty("b", Json.Number(2))), Json.ObjectParams( new JsonProperty("a", Json.Number(3)), new JsonProperty("b", Json.Number(3))))) .Should().BeTrue(); }
public void CanPopulateExportableCtor() { //Arrange Compose <IAnimal> .Exports.Clear(); Compose <IManager> .Exports.Clear(); Compose <IZoo> .Exports.Clear(); Compose <ICar> .Exports.Clear(); Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Dog)); Compose <IAnimal> .Add(typeof(Cat)); Compose <IZoo> .Add(typeof(DallasZoo)); Compose <IManager> .Add(typeof(MrJones)); Compose <ICar> .Add(typeof(Car)); //Act var ctorInfo = typeof(Cat).GetExportableConstructor(); var parameters = ctorInfo.GetCtorParameters(); var obj = (Cat)ctorInfo.Invoke(parameters); // Assert Assert.True(obj != null && obj.Manager != null && obj.Zoo != null); }
public void CanGetInstanceWithExportableCtor() { //Arrange Compose <IAnimal> .Exports.Clear(); Compose <IManager> .Exports.Clear(); Compose <IZoo> .Exports.Clear(); Compose <ICar> .Exports.Clear(); Compose <IAnimal> .Add(typeof(Lion)); Compose <IAnimal> .Add(typeof(Dog)); Compose <IAnimal> .Add(typeof(Cat)); Compose <ICar> .Add(typeof(Car)); Compose <IZoo> .Add(typeof(DallasZoo)); Compose <IManager> .Add(typeof(MrJones)); //Act var obj = ReflectionHelpers.GetInstance <Cat>(); // Assert Assert.True(obj != null && obj.Manager != null && obj.Manager.Car != null && obj.Zoo != null); }
public override void Initialize() { CreatableTypes() .Concat(extra.SelectMany(CreatableTypes)) .EndingWith("Service") .AsInterfaces() .RegisterAsLazySingleton(); Mvx.LazyConstructAndRegisterSingleton <IDalContainer, DalContainer>(); Mvx.LazyConstructAndRegisterSingleton <IConfigReader, ConfigContainer>(); Mvx.LazyConstructAndRegisterSingleton <IConfigContainer, ConfigContainer>(); Mvx.LazyConstructAndRegisterSingleton <ILog, EmptyLogger>(); // Mvx.LazyConstructAndRegisterSingleton<ISlackConnector, FakeSlack>(); // ModelContext is injected on a IMiddleware and has a not-so-DI friendly constructor. Mvx.LazyConstructAndRegisterSingleton(() => Mvx.Resolve <IDalContainer>().Context); using (var ioc = new MvxSimpleIocImprovedCreator(CreatableTypes)) { Compose <IMvxImprovedConfig, IMvxImprovedLocatorConfig, IMvxImprovedRegistry, IMvxSimpleContainer> .NoobotCore(ioc.Registry); } RegisterCustomAppStart <MyNavigationAppStart>(); }
public TestCaseEditorCompose() { random = new Random(1337); Add(compose = new Compose()); AddStep("Next beatmap", nextBeatmap); }
public void OnReply(Tweet tweet, string screenName) { if (tweet == null) { return; } if (tweet.IsDirectMessage) { Compose.ShowDirectMessage(tweet.ScreenName); } else { var matches = new Regex(@"(?<=^|(?<=[^a-zA-Z0-9-_\.]))@([A-Za-z]+[A-Za-z0-9_]+)") .Matches(tweet.Text); var names = matches .Cast <Match>() .Where(m => m.Groups[1].Value != tweet.ScreenName) .Where(m => m.Groups[1].Value != screenName) .Select(m => "@" + m.Groups[1].Value) .Distinct(); var replyTos = string.Join(" ", names); var message = string.Format("@{0} {1}{2}", tweet.ScreenName, replyTos, (replyTos.Length > 0) ? " " : ""); Compose.Show(message, tweet.StatusId); } }
internal bool LoadReferenceFile(Beatmap map) { if (Compose.ReferenceHitObjectManager != null) { Compose.ReferenceHitObjectManager.Dispose(); Compose.ReferenceHitObjectManager = null; } try { if (map == null) { //Clear the reference sprites Compose.ReferenceChanged(); return(false); } Compose.ReferenceHitObjectManager = new HitObjectManagerEditor(); Compose.ReferenceHitObjectManager.SetBeatmap(map, Mods.None); Compose.ReferenceHitObjectManager.Load(true); Compose.ReferenceHitObjectManager.ManiaStage = new StageMania(Compose.ReferenceHitObjectManager); Compose.ReferenceChanged(); return(true); } catch (Exception e) { Compose.ReferenceChanged(); return(false); } }
private void ComposeOnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { OnRenderSizeChanged(new SizeChangedInfo(this, new Size(Width, Height), true, true)); if (Compose.IsVisible) { Compose.Focus(); } }
public static Enhancer <T> ApplyMiddleware(params Middleware <T> [] middlewares) => (createStore) => (reducer, initialState, enhancer) => { var store = createStore(reducer, initialState, enhancer); if (middlewares == null || middlewares.Length == 0) { return(store); } var dispatch = store.Dispatch; var chain = middlewares.Select(m => m(store)) .ToList(); var newDispatch = Compose(chain) (dispatch); return(store.ReplaceDispatch(newDispatch)); };
public static Data.DAO.Compose Map(Compose value) { return(new Data.DAO.Compose { Actions = value.Actions != null?MapperActions.Map(value.Actions) : null, Scenario = value.Scenario != null?MapperScenario.Map(value.Scenario) : null }); }
public void CreateDraft(string recipient, string subj, string message) { DraftFolder.Click(); Compose.Click(); Recipients.SendKeys(recipient); Subject.SendKeys(subj); Text.SendKeys(message); Close.Click(); }
private static IEnumerable <TestItem> BooleanTests() { yield return(new TestItem( ". | not", Compose.AllParams(new Identity(), new FunctionCall(new FunctionName("not", 0))))); yield return(new TestItem( "true or false", new FunctionCall(Or.Builtin, new Literal(true), new Literal(false)))); yield return(new TestItem( "true and false", new FunctionCall(And.Builtin, new Literal(true), new Literal(false)))); yield return(new TestItem( "true or false and true", new FunctionCall( Or.Builtin, new Literal(true), new FunctionCall( And.Builtin, new Literal(false), new Literal(true))))); yield return(new TestItem( "true or false or true", new FunctionCall( Or.Builtin, new FunctionCall( Or.Builtin, new Literal(true), new Literal(false)), new Literal(true)))); yield return(new TestItem( "true and false and true", new FunctionCall( And.Builtin, new FunctionCall( And.Builtin, new Literal(true), new Literal(false)), new Literal(true)))); yield return(new TestItem( "true and false or false and true", new FunctionCall( Or.Builtin, new FunctionCall( And.Builtin, new Literal(true), new Literal(false)), new FunctionCall( And.Builtin, new Literal(false), new Literal(true))))); }
private void load(OsuGameBase osuGame) { osuGame.Beatmap.Value = new TestWorkingBeatmap(new OsuRuleset().RulesetInfo); var compose = new Compose(); compose.Beatmap.BindTo(osuGame.Beatmap); Child = compose; }
private static void Refresh() { if (Compose == null || Compose.GetInvocationList().Length == 0) { Stop(); } else { Start(); } }
public void TestEmptySecondInComposition() { // Arrange var data = MakeNestedArray(); var op = Compose.AllParams(new Identity(), new FunctionCall(Empty.Builtin)); // Act var result = op.RunAsSequence(data); // Assert result.Count().Should().Be(0); }
public void IdentityInSequence() { // Arrange var data = MakeArray(); var op = Compose.AllParams(new Identity()); // Act var result = op.RunAsScalar(data); // Assert result.DeepEqual(data).Should().BeTrue(); }
public void EmptySequence() { // Arrange Json data = MakeArray(); var op = Compose.AllParams(); // Act var result = op.RunAsScalar(data); // Assert result.DeepEqual(data).Should().BeTrue(); }
public void CanGetPropertySingleton() { Compose <IZoo> .Exports.Clear(); //Register/Act Compose <IZoo> .Add(typeof(BostonZoo)); // Act var zoo = Compose <IZoo> .Singleton; //Assert Assert.True(zoo != null && zoo.Name == "Babaam"); }