来自OO背景,我在试图避免变异时如何解决FP的简单问题时遇到了麻烦.
let mutable run = true
let player1List = ["he"; "ho"; "ha"]
let addValue lst value =
value :: lst
while run do
let input = Console.ReadLine()
addValue player1List input |> printfn "%A"
if player1List.Length > 5 then
run <- false
printfn "all done" // daz never gunna happen
Run Code Online (Sandbox Code Playgroud)
我知道在某些情况下使用变异是可以的,但我正在努力训练自己以避免突变作为默认值.有了这个说,有人可以告诉我一个上面没有使用F#突变的例子吗?
最终的结果应该是player1List继续增长,直到项目的长度为6,然后退出并打印'all done'
I'm getting these errors:
java.lang.IllegalArgumentException: Mutation of 16.000MiB is too large for the maximum size of 16.000MiB
in Apache Cassandra 3.x. I'm doing inserts of 4MB or 8MB blobs, but not anything greater than 8MB. Why am I hitting the 16MB limit? Is Cassandra batching up multiple writes (inserts) and creating a "mutation" that is too large? (If so, why would it do that, since the configured limit is 8MB?)
关于突变的文献很少-只是说突变是插入或删除。如何防止这些错误?
我想在事件处理程序中使用突变。我的事件定义如下:
(JSX attribute) onOk?: ((e: React.MouseEvent<any, MouseEvent>) => void) | undefined
Run Code Online (Sandbox Code Playgroud)
这就是我从客户端调用突变的方式
export const IMPORT_INFO_MUTATION = gql`
mutation ImportPolicy($data: ImportPolicyInput!) {
importPolicy(data:$data)
{
_id
name
}
}
Run Code Online (Sandbox Code Playgroud)
最终我这样称呼它:
onOk={() => {
useImportPolicyMutation({
variables: {
data: {
jsonData: JSON.parse(importPolicyData)
}
},
})
}
Run Code Online (Sandbox Code Playgroud)
`不用担心突变中的变量和参数。他们很好。问题是我收到以下错误:
Unhandled Rejection (Invariant Violation): Invalid hook call. Hooks can only
be called inside of the body of a function component. This could happen for
one of the following reasons:
1. You might have mismatching versions of React …Run Code Online (Sandbox Code Playgroud) 我有一个对象作为查询参数存储为 url 中的键值对。该对象的键可能会更改,我想使用该对象中的每个键、值对来更新stateredux 应用程序中对象的键、值对。我需要以不改变state对象的方式这样做,目前我正试图实现这个目标,如下所示:
case 'LOAD_SEARCH_FROM_URL':
let _state = Object.assign({}, state);
const args = action.obj.substring(1).split('&');
args.map((arg) => {
const split = arg.split('=');
_state = Object.assign({}, _state, {
[split[0]]: JSON.parse( decodeURIComponent( split[1] ) )
})
})
return _state;
Run Code Online (Sandbox Code Playgroud)
这在简单的测试中工作正常,但我想确保这实际上没有执行任何突变。我将不胜感激其他人可以在这个问题上提供的任何见解!
为什么可变数据结构和其他可变性用IO函数式语言来表示?我正在看例如 Haskell'sIORef或 Idris' IOArray。
我不认为这是一个历史或设计问题。我不太明白为什么IO适合突变 - 或者更确切地说,为什么突变封装在IO.
language-agnostic haskell functional-programming in-place mutation
我的一个同事向我展示了一个有趣的片段,其中一个对象内声明的var没有被对象的成员变异.如果有人解释为什么这样做会很好.代码如下:
object SomeObject{
var count = 1
def addToCount = count + 1
def printCurrentCount:Unit = {addToCount;println(count)}
}
// Exiting paste mode, now interpreting.
defined module SomeObject
scala> SomeObject.printCurrentCount
1
Run Code Online (Sandbox Code Playgroud)
不应该printCurrentCount打印变异的var计数为2?
我localStorage用来设置和获取项目,这些项目放在.vue文件中的javascript代码中。但是,我想以某种方式访问该存储并将其放置在另一个文件中的Vuex存储部分中,最好是在突变中。
如果有人知道该怎么做,请您能帮忙吗?下面是我正在使用的localStorage的代码。
if(response.status === 200){
console.log('TOKEN_SET', response)
this.access_token = response.data.access_token
localStorage.setItem(this.access_token, JSON.stringify(this.access_token));
};
mounted(){
console.log('GOT_TOKEN')
if(localStorage.getItem(this.access_token)) this.access_token = JSON.parse(localStorage.getItem(this.access_token))
}
Run Code Online (Sandbox Code Playgroud) 我想将 HTTP POST 值直接作为 JSON 发送到已在我的 GraphQL Mutation 中声明的 addBook 解析器。
但是,我见过(并证明)的示例使用从 JSON 到 SDL 的参数序列化或在 SDL 中重新声明变量以从查询变量进行绑定。
这两种方法都没有意义,因为 addBook 突变已经声明了所有参数和验证。使用这些方法将导致必须创建、调试和维护不必要的查询序列化逻辑。
我在浏览器中构造了格式良好(模式编辑和验证)的 JSON,它符合声明的 GraphQLObjectType 的数据。
谁能解释在针对突变解析器发布时如何避免这种不必要的重新序列化或重复?
我一直在尝试使用多种方法将 JSON 数据结构映射到 addBook 突变,但找不到简单发送 JSON 的示例,以便将属性名称绑定到 addBook 参数名称,而没有明显毫无意义的重新序列化或样板。
https://github.com/cefn/graphql-gist/tree/master/mutation-map 上的源代码是一个最小的可重现示例,它演示了该问题。它有一个 addBook 解析器,它已经定义了参数名称、类型和可空性。我找不到使用 JSON 来简单地针对 addBook POST 参数的方法。
我使用 GraphiQL 作为 HTTP POST 值的参考实现。
我可以编写代码将 JSON 序列化为 SDL。它最终看起来像这样,它通过 GraphiQL 工作:
mutation {addBook(id:"4", name:"Education Course Guide", genre: "Education"){
id
}}
Run Code Online (Sandbox Code Playgroud)
或者,我可以编写代码将 addBook 的每个参数显式别名为不同的查询,然后允许我将值作为 JSON 查询变量发布,也通过 GraphiQL 证明:
mutation doAdd($id: String, $name: String!, $genre: String){ …Run Code Online (Sandbox Code Playgroud) 我坚持使用一个应该计算字符串中大写字母的函数。但计数器的结果却是 0,我不知道我在哪里犯了错误。
const bigLettersCount = (str) => {
let result = 0;
for (let i = 0; i < str.length; i += 1) {
if (str[i].toUpperCase() === str[i]) {
result += i;
}
return result;
}
}
bigLettersCount('HeLLo')
Run Code Online (Sandbox Code Playgroud) 我需要一些帮助来解释从第5行到第9行的含义.谢谢
String words = "Rain Rain go away";
String mutation1, mutation2, mutation3, mutation4;
mutation1 = words.toUpperCase();
System.out.println ("** " + mutation1 + " Nursery Rhyme **");
mutation1 = words.concat ("\nCome again another day");
mutation2 = "Johnny Johnny wants to play";
mutation3 = mutation2.replace (mutation2.charAt(5), 'i');
mutation4 = mutation3.substring (7, 27);
System.out.print ("\'" + mutation1 + "\n" + mutation4 + "\'\n");
System.out.println ("Title length: " + words.length());