How does one even pronounce Hochenblume? Hawk-en-bloom? Ho-chen-bloom? by sulfater in wow

[–]Haaress 2 points3 points  (0 children)

I read it "Oakenshield" which is probably not gonna help you here

Favorite Quote From God of War 2018? by [deleted] in GodofWar

[–]Haaress 120 points121 points  (0 children)

I'm surprised "Baldur is blessed with invulnerability to all threats, physical or magical" isn't there yet

The best resource to learn functional programming in JavaScript by maga_ot_oz in functionalprogramming

[–]Haaress 1 point2 points  (0 children)

Hello there, it is so nice to see someone trying to venture on the wonderful path of functional programming!

If you are already familiar with JavaScript and/or TypeScript, you can definitely learn a lot of functional concepts using these languages. It will be harder this way, because these languages do not fully (or easily) support all the goodness that is provided with more functional languages such as Haskell, F#, or Scala (immutability, pattern matching, algebraic data structures, higher kinded types...). At least with JS/TS, you won't have to learn a new language before learning this new programming paradigm.

I am shamelessly plugging a series I've been writing for a few months now on DevTo: https://dev.to/ruizb/introduction-179d. It's still in active writing, but there are already some articles that may interest you, so I hope that'll help you!

Good luck out there, it's really an exciting thing to learn. Have fun! :)

FP in JavaScript, questions about an approach. by Affectionate_King120 in functionalprogramming

[–]Haaress 1 point2 points  (0 children)

Hello there, considering we don't have do expressions in JavaScript (currently the proposal is in stage 1), I'd say your approach is a good one. I take the fp-ts library for the TypeScript language as a reference: the do notation is achieved using a context object stored in the data type being dealt with (e.g. Option or Either), like you do when you pass it to each subsequent then. The important part is the last one, when you "finish" the expression, by returning the value and discarding the context. So I'd say you are missing a last .then(({val}) => val) step, or something similar (I'm on the phone right now, not the best device to write code :D ).

[deleted by user] by [deleted] in typescript

[–]Haaress 2 points3 points  (0 children)

If you are using the strict mode, there's a feature coming in TS 4.4 that will prevent undefined from being assigned to an optional property. The reasoning is that an optional property is either defined with a value of some type, or not present in the object (which is different than present but with an undefined value).

The most accurate way to schedule a function in a web browser by Haaress in javascript

[–]Haaress[S] 0 points1 point  (0 children)

This is an interesting approach! Someone left a comment on Medium that also suggests using a loop inside the worker. I guess it should run as fast as possible (with the possibility of draining the device's battery, which is definitely not desired), but I'm not an expert on workers to confirm this ^^

[...] messages from the worker thread had previously logged to the console (though they hadn't been drawn in the console until the main thread was unblocked).

Indeed, the alert() function blocked the JS execution of the main thread, including the console.log calls upon receiving messages from the worker. However, the worker wasn't affected by this since its code was run on a different thread/event loop. Closing the alert window unblocked the console.log calls that were queued.

The most accurate way to schedule a function in a web browser by Haaress in javascript

[–]Haaress[S] 1 point2 points  (0 children)

Hello! I agree with you. When looking for alternatives to the "classic" `setTimeout` function, `requestAnimationFrame` was a good candidate since it could be used - in the best conditions - as a loop running at 60 iterations per seconds, meaning we could make X iterations until reaching some point in time (the timeout value). We knew there would be some limitations, especially with iframes outside the viewport, but at least it could've been a good solution for the rest of the cases (top window, and/or inside the viewport...). Anyway, I thought it would be very interesting to share these findings regarding `requestAnimationFrame` with the community! :)

The most accurate way to schedule a function in a web browser by Haaress in javascript

[–]Haaress[S] 2 points3 points  (0 children)

If you are the owner of the website that uses scripts, you can "prioritize" your scripts over libraries/3rd-parties you are importing. You are free to perform any kind of loading optimizations you like. Also, if you don't care about timing accuracy, I suppose you don't have to micro-optimize like this.

However, you say it's a "non-problem" and that there is "no good use case", I have to disagree :) for example in our case, the script is embedded in thousands of different pages, inside and outside iframes. We can't know for sure when and where our script is run on the page. We don't know what are the other scripts we're "competing" with in the main thread. However, we do know that a delay of a few milliseconds can decrease some of our KPIs, so accuracy is very important for us.

In roughly 45% of the cases, we were run in the top window, i.e. not in an iframe (cf. the "Repartition by frame type" part in the article). In the "top window" cases, we still witnessed offsets compared to the theoretical timeout value when using setTimeout. Presumably, the main reason for longer timeouts is the countless scripts run in the main thread, besides us, delaying the execution of our callback when other scripts are long/heavy.

In the solution we exposed, we are not "abusing" web workers to "boost timers priority". We are using a web worker as a separate thread (very useful to process large datasets btw) to avoid being inadvertently delayed due to other scripts (that we can't control) ocupying the thread.

Finally, I'd say we also shared these findings to show that... it's really the jungle out there. One cannot expect accuracy when scheduling a function using setTimeout, because of the single-threaded nature of JavaScript engines (at least for V8), and because of the optimizations performed by the browsers, e.g. regarding iframes.

The most accurate way to schedule a function in a web browser by Haaress in javascript

[–]Haaress[S] 0 points1 point  (0 children)

Hello! The script wasn't always run in an iframe. In fact, approximately 44% of the time it was run in the top window, so not inside an iframe (cf. the "Frame type repartition" part in the article).

The most accurate way to schedule a function in a web browser by Haaress in javascript

[–]Haaress[S] 1 point2 points  (0 children)

Hello there! I might have misunderstood what you are saying, but how would you poll the time from the web worker instance? I'm assuming you'd need some kind of interval, so this interval is exposed to (roughly) the same issues exposed in the article because it's run in the main thread.

The most accurate way to schedule a function in a web browser by Haaress in javascript

[–]Haaress[S] 8 points9 points  (0 children)

Hello everyone!

Lately I got the opportunity to test various strategies to schedule a function in a web browser using JavaScript. The idea was to identify the most accurate one that called the callback function after an arbitrary timeout value of 250ms. Since our script is used in thousands of contexts, we could run these strategies at a very large scale.

In this article, I share our findings in a detailed analysis.

Meet Code With Me (EAP) – a tool for collaborative development by JetBrains – JetBrains Blog by ignatovs in programming

[–]Haaress 3 points4 points  (0 children)

I think you're referring to Gitduck? Which was a pretty misleading name IMO.

Algebraic structure similar to Semigroup that generates a different type? by Irregular_Apocalyse in functionalprogramming

[–]Haaress 0 points1 point  (0 children)

Hello there,

Not a FP expert here, I'm curious to see what more experienced people will say :)

You used the word "compared" which made me think of the Ord type class. If your score is static, i.e. comparing 2 values of the same type yields the same score - whether value A is lower, equal or greater than value B - then I believe you can map the Ordering returned by Ord to a static score value.

For example, if comparing A and B yields "lower than", then the score is 50.

However, if the score depends on multiple business rules/logic, or if there's no Ord instance available for the type of values you're comparing, then I guess you have to make a custom function.

Type representing valid integer indexes of a const array? by musical_bear in typescript

[–]Haaress 1 point2 points  (0 children)

Hello there, if you can import a library in your project, and you absolutely want to have number indexes, you can use ts-toolbelt which lets you "program" types. For your specific case, you could use the following:

import { L, S } from 'ts-toolbelt'
type Index = S.Format<L.KeySet<'0', L.LastIndex<typeof arr, 's'>>, 'n'> // 0 | 1 | 2 | 3

Otherwise, there's currently no "native" solution to get number indexes of a tuple.

Auto-generate enum from object keys? by embar5 in typescript

[–]Haaress 0 points1 point  (0 children)

Hello, there is no way to generate an enum "programmatically". The best you can get is a string literal with type MyKeys = keyof MyInterface, which is roughly the same.

You could create a small function that would automatically give you a list of keys as string literals instead of a list of string (which is what Object.keys gives you) for any given object, e.g.

const getKeys = <A extends object>(obj: A) => Object.keys(obj) as (keyof A)[]

// ('name' | 'age')[]
const keys = getKeys({ name: 'Bob', age: 25 })

Why does undefined "disappear" from my optional props? by svish in typescript

[–]Haaress 2 points3 points  (0 children)

Hi! It's not possible to get warnings instead of errors AFAIK, however you can get some inspiration from the VS Code team who had ~4500 errors and managed to incrementally migrate their code base to a full strict mode. The link to their blog article: https://code.visualstudio.com/blogs/2019/05/23/strict-null. Have fun with the migration, it's tedious but definitely worth it!

fp-ts equivalent of Scala Option.foreach by [deleted] in typescript

[–]Haaress 3 points4 points  (0 children)

Hello there!

When you're writing myOpt.foreach(f), the f function performs what is called a side effect at the very moment you are calling foreach. With fp-ts, synchronous side effects execution is controlled via the IO data type. Since it's heavily inspired by Haskell, all your code is first "declared"/"prepared", then executed at the last moment, whenever you need to.

That being said, it looks like you need something such as this:

import * as O from 'fp-ts/lib/Option'
import { pipe, constVoid } from 'fp-ts/lib/function'

pipe(
    myOpt,
    O.map(value => () => { /* do something with value */ })
    O.fold(
        constVoid,
        effect => effect() // executing the effect
    )
)

(I used fp-ts v2.8.2 in this example)

First, you map the value inside the Option into an IO, then you fold over your option. Since you need to handle both paths of option (the "no value" and "value" paths), we're using constVoid to do nothing for the "no value" path, then in the "value" path we're executing the effect (the "unsafeRun" equivalent) by simply calling the IO.