public static void Process(Tagged <Direction, int> d) => d.Switch(t => t.Tag) .Case(Direction.North, _ => WriteLine("North")) .Case(Direction.South, _ => WriteLine("South")) .Case(Direction.East, _ => WriteLine("East")) .Case(Direction.West, _ => WriteLine("West")) .Case(Direction.Degree, t => WriteLine($"{t.Value}")) .Else(_ => WriteLine("Unmatched"));
void Shoot() { timer = 0; laserLine.enabled = true; laserLight.enabled = true; laserLine.SetPosition(0, transform.position); shootRay.origin = transform.position; shootRay.direction = transform.forward; // Perform the raycast against gameobjects on the shootable layer and if it hits something... if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { // Set the second position of the line renderer to the point the raycast hit. laserLine.SetPosition(1, shootHit.point); Playerhit = shootHit.collider.GetComponent <Tagged> (); if (Playerhit != null) { Playerhit.It = true; self.It = false; } } // If the raycast didn't hit anything on the shootable layer... else { // ... set the second position of the line renderer to the fullest extent of the gun's range. laserLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
public void TestConstrainedGenericMethod() { Tagged obj = new Tagged("foo, bar"); MockActivator a = ActivatorFor(obj); Assert.AreEqual("foo, bar", GenericMethods.ConstrainedMethod(obj)); Assert.AreEqual(1, a.ReadCount); }
private void InitializeItems() { All.Initialize(); Unread.Initialize(); Private_.Initialize(); Public_.Initialize(); Untagged.Initialize(); Tagged.Initialize(); }
public void EventAdapter_should_unwrap_when_reading() { var e = new UserDataChanged("name", 42); var tagged = new Tagged(e, new HashSet <string> { "adult" }); ToJournal(e).ShouldBe(tagged); FromJournal(tagged, string.Empty).ShouldBe(new SingleEventSequence(e)); }
// Creates relationship between post and tag and between user and tag public void CreateTaggedRelationship(Tagged tagged) { var query = client.Cypher .Match("(post:Post)", "(user:User)") .Where((Post post) => post.id == tagged.post.id) .AndWhere((User user) => user.username == tagged.tagged.username) .Create("(post)-[r:TAGGED {time: '" + tagged.time + "'}]->(user)"); query.ExecuteWithoutResults(); }
void Awake() { laserLine = GetComponent <LineRenderer> (); laserLight = GetComponent <Light> (); // Create a layer mask for the Shootable layer. shootableMask = LayerMask.GetMask("Shootable"); self = GetComponentInParent <Tagged> (); }
private void SetTagged() { if (currentTag == null) { Tagged = new ObservableItems <BookmarkItemViewModel>(service.taggedItems); } else { Tagged = new ObservableItems <BookmarkItemViewModel>(service.allItems.Where(x => x.Tags.Contains(currentTag)).ToList()); } Tagged.Initialize(); }
public void TestBindSameActivator() { Tagged obj = new Tagged("test"); MockActivator ma = ActivatorFor(obj); IActivatable activatable = (IActivatable)obj; activatable.Bind(ma); string tags = obj.tags; Assert.AreEqual(1, ma.ReadCount); }
public void TestBindDifferentActivator() { Tagged obj = new Tagged("test"); MockActivator ma = ActivatorFor(obj); IActivatable activatable = (IActivatable)obj; Assert.Expect( typeof(InvalidOperationException), delegate { activatable.Bind(ActivatorFor(obj)); }); }
public async Task <ActionResult> Put(Guid id, [FromBody] Tag tag) { try { _log.Information("Add tag to Books requested on {Date}", DateTime.Now); var tagFromDb = await _context.Tags.FirstOrDefaultAsync(x => x.Name == tag.Name); var bookFromDb = await _context.Books.FirstOrDefaultAsync(x => x.Id == id); if (bookFromDb == null) { return(BadRequest("Book not found".ToBadRequest())); } if (tagFromDb != null) { var asso = await _context.Taggeds.FirstOrDefaultAsync(x => x.BookId == id || x.TagId == tagFromDb.Id); if (asso != null) { return(Ok(Format.ToMessage("Success", 200))); } var newAssociation = new Tagged { TagId = tagFromDb.Id, BookId = id }; _context.Taggeds.Add(newAssociation); await _context.SaveChangesAsync(); return(Ok(Format.ToMessage("Success", 200))); } if (!ModelState.IsValid) { return(BadRequest(ModelState.ToBadRequest(400))); } _context.Tags.Add(tag); await _context.SaveChangesAsync(); var newTagged = new Tagged { TagId = tag.Id, BookId = id }; _context.Taggeds.Add(newTagged); await _context.SaveChangesAsync(); return(Ok(Format.ToMessage("Success", 200))); } catch (Exception e) { _log.Fatal(e.Message + "on Get Books on {Date}", DateTime.Now); return(StatusCode(500)); } }
void Awake() { player1 = GameObject.Find("Player1"); p1Tag = player1.GetComponent <Tagged> (); player2 = GameObject.Find("Player2"); p2Tag = player2.GetComponent <Tagged> (); HUD = GameObject.Find("HUD"); scores = HUD.GetComponentsInChildren <Text> (); }
void Awake() { player = GameObject.FindGameObjectWithTag("Player").transform; nav = GetComponent <NavMeshAgent>(); tagged = GetComponent <Tagged> (); anim = GetComponent <Animator>(); p = menu.GetComponent <PauseManager>(); rb = GetComponent <Rigidbody> (); }
static void Main(string[] args) { //var tupleLens = Lens<(string, int), int>.Of(s => s.Item2, (a, s) => (s.Item1, a)); //Console.WriteLine(tupleLens.Set(3, ("abc", 2))); ////var prismSubject = Prism<Person, Maybe<Subject>>.Of(s => { return s.IsStudent == true ? Just(s.Subject) : Nothing<Subject>(); }, (a, s) => s.IsStudent == true ? new Person()); BinaryOp rectArea = RectArea; BinaryOp squareArea = SquareArea; BinaryOp comb = rectArea + squareArea; //comb += rectArea; //comb += squareArea; WriteLine("---------------"); //foreach (BinaryOp f in comb.GetInvocationList()) { // WriteLine(f(3, 4)); //} WriteLine(comb(4, 7)); WriteLine("---------------"); //List(1, 2, 3) //.Map(x => x + 1) //.DebugPrint(); //Just(1) // .Map(x => x + 2) // .DebugPrint(); //Right<string, int>(1)because most IDEs can be setup to auto line wrap code for those that prefer it // .Map(x => x + 1) // .DebugPrint(); //Success<string, int>(1) // .Map(x => x + 1) // .DebugPrint(); //Of(1) // .Map(x => x + 1) // .DebugPrint(); //List(1, 2, 3).ToCoyo<List<int>, List<int>>() // .Map(xs => xs.Map(x => x.ToString() + " World!")) // .Run() // .DebugPrint(); //List(1).ToYoneda<int>() //.Map(x => x + 1) //.RunIEnumerable() //.DebugPrint(); //Console.WriteLine("Hello World!"); //var read = IO<string>.Of(() => Console.ReadLine()); //var write = Fun<string, IO<int>>(v => IO<int>.Of(() => { // Console.WriteLine(v); // return 0; //})); //var blah1 = from _1 in write("What's your name?") // from name in read // from _2 in write($"Hi {name}, what's your surname?") // from surname in read // select $"{name} {surname}"; //var blah2 = Fun(() => { // Console.WriteLine("What's your name?"); // var name = Console.ReadLine(); // Console.WriteLine($"Hi {name}, what's your surname?"); // var surname = Console.ReadLine(); // return $"{name} {surname}"; //}); //Console.WriteLine(blah2()); //Console.WriteLine(blah1.Compute()); //var pgm2 = Fun<int, string, int, string, string>((u, v, w, x) => $"{v} {x}") // .LiftM(write("What is your name?"), read, write("what's your surname?"), read); //Console.WriteLine(pgm2.Compute()); //var firstname = "Jack"; //var lastname = "Sprat"; //Func<string, string> title = prefix => { // return $"{prefix} {firstname}, {lastname}"; //}; //Console.WriteLine(title("Mr")); // "Mr Jack, Sprat" string greeting = ""; Action <string> greet = name => { greeting = $"Hi, {name}"; }; greet("Brian"); Console.WriteLine(greeting); // "Hi, Brian" //var abs = Math.Abs(Math.Abs(-3)); //var input = new List<int> { 2, 1, 3, 4, 6, 5 }; //Func<int, int> id = x => x; //var output = input.Map(id); //output.DebugPrint(); IEnumerable <T> AlternationOf <T>(Func <int, T> fn, int n) => Enumerable.Range(n, n).Select(fn); //string VowelPattern(int v) => "aeiou".ToCharArray().Map(x => x.ToString()).ToList()[v % 5]; string BinaryPattern(int v) => (v % 2).ToString(); IEnumerable <string> BinaryAlternation(int n) => AlternationOf(BinaryPattern, n); string BinaryLine(int n) => BinaryAlternation(n).Join(" "); string BinaryTriangle(int n) => Enumerable.Range(1, n).Map(BinaryLine).Join("\n"); string BinarySquare(int n) => Enumerable.Range(1, n).Map(x => BinaryLine(n)).Join("\n"); WriteLine(BinaryLine(3)); WriteLine(BinaryTriangle(4)); WriteLine(BinarySquare(5)); Measure("Functional1", 10, () => { int sum3or5(int a, int e) => (e % 3 == 0 || e % 5 == 0) ? a + e : a; return(Enumerable.Range(0, 1000) .Aggregate(sum3or5)); }); Measure("Functional2", 10, () => { return(Enumerable.Range(0, 1000) .Aggregate((a, e) => e.IsMultipleOf().ForEither(3, 5) ? a + e : a)); }); Measure("Functional3", 10, () => { return(Enumerable.Range(0, 1000) .Where(e => e.IsMultipleOf().ForEither(3, 5)) .Sum()); }); Measure("Imperative1", 10, () => { var total = 0; for (int i = 1; i < 1000; i++) { if (i % 3 == 0 || i % 5 == 0) { total += i; } } return(total); }); Measure("Imperative2", 10, () => { var total = 0; foreach (var v in Enumerable.Range(0, 1000)) { total += (v % 3 == 0 || v % 5 == 0) ? v : 0; } return(total); }); //var t = Try(() => "test") // .Bind(a => Try<string>(() => throw new Exception())) // .Bind(a => Try(a.ToUpper)); //var numbers = List(List(1), List(2), List(3), List(4), List(5)); var numbers = List(1, 2, 3, 4, 5); //numbers.DebugPrint(); var right = Right <string, string>("success"); right.DebugPrint(); var identity = Of("id1"); identity.DebugPrint(); Person num = null; var maybe = Just(num); maybe.DebugPrint(); var reader = 2.ToReader < string, int > (); reader.DebugPrint(); var validation = Success <string, int>(2); validation.DebugPrint(); var blah = Fun((string a) => WriteLine(a)); blah("Hello World"); var is3or5 = Fun((int a) => a.IsMultipleOf().ForEither(3, 5)); var p = new Point(2, 3); var(x1, y1) = p; var shoppingList = new[] { new { name = "Orange", units = 2.0, price = 10.99, type = "Fruit" }, new { name = "Lemon", units = 1.0, price = 15.99, type = "Fruit" }, new { name = "Apple", units = 4.0, price = 15.99, type = "Fruit" }, new { name = "Fish", units = 1.5, price = 45.99, type = "Meat" }, new { name = "Pork", units = 1.0, price = 38.99, type = "Meat" }, new { name = "Lamb", units = 0.75, price = 56.99, type = "Meat" }, new { name = "Chicken", units = 1.0, price = 35.99, type = "Meat" } }; var ITotal = 0.0; // identity value / seed value for (int i = 0; i < shoppingList.Count(); i++) { if (shoppingList[i].type == "Fruit") // predicate / where { ITotal += shoppingList[i].units * shoppingList[i].price; // reducer / aggregation } } WriteLine($"total = {ITotal}"); var FTotal1 = shoppingList.Fold(0.0, (a, e) => e.type == "Fruit" ? a + e.units * e.price : a); WriteLine($"fruit total = {FTotal1}"); var FTotal2 = shoppingList.Where(x => x.type == "Fruit").Sum(x => x.units * x.price); WriteLine($"fruit total = {FTotal2}"); var Mathematics = Tagged(Subject.Mathematics, 70); var Science = Tagged(Subject.Science, (60, 70, 80)); var Economics = Tagged(Subject.Economics, (60, 70)); var Medicine = Tagged(Subject.Medicine, ("ted", 65, 75.5)); Mathematics .Map(x => x * 1.1) .DebugPrint(); Science .Map(x => (x.Item1 * 1.1, x.Item2 * 1.2, x.Item3 * 1.3)) .DebugPrint(); Economics .DebugPrint(); Economics.Switch(t => t.Tag) .Case(Subject.Mathematics, t => WriteLine($"Mathematics: {t}")) .Case(Subject.Economics, t => WriteLine($"Economics: {t}")) .Case(Subject.Science, t => WriteLine($"Science: {t}")) .Else(_ => WriteLine("Default: No Match")); var res21 = Mathematics.Switch <Tagged <Subject, int>, Subject, int>(t => t.Tag) .Case(Subject.Mathematics, t => { WriteLine($"Mathematics: {t.Value}"); return(t.Value); }) .Case(Subject.Economics, t => { WriteLine($"Economics: {t.Value}"); return(t.Value); }) .Case(Subject.Science, t => { WriteLine($"Science: {t.Value}"); return(t.Value); }) .Else(_ => { WriteLine("Default: No Match"); return(default); });
public void push(Tagged part) { parts.Add(part); }